Class SortedUnionPipe<T>

  • Type Parameters:
    T - The data type of the items this pipe works with
    All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe, Pipe<T>

    public class SortedUnionPipe<T>
    extends MultiSortedBasePipe<T>
    An intermediate pipe performing set union operation on a collection of sorted input pipes. The input pipes must have the same item data type, and must all be ordered by the same order relation. The order relation (comparator) must be consistent with equality (java's Object.equals): a equals b if and only if compare(a,b) == 0. Input pipes may have item repetitions, but they are always treated as sets, where repetitions make no difference. The output of the pipe is always sorted and includes no duplicates.
    Author:
    Eyal Schneider
    • Constructor Detail

      • SortedUnionPipe

        public SortedUnionPipe​(List<? extends Pipe<T>> inputPipes,
                               Comparator<? super T> comparator)
        Constructor
        Parameters:
        inputPipes - The input pipes. Each of them must be sorted by the order defined in the provided comparator, and items may have duplicates.
        comparator - The total order relation to use when merging the data from the different input pipes. Should be consistent with the ordering of the input pipes. IMPORTANT NOTE: comparator must be consistent with equals: a.equals(b) if and only if comparator.compare(a,b)==0.
      • SortedUnionPipe

        @SafeVarargs
        public SortedUnionPipe​(Comparator<? super T> comparator,
                               Pipe<T>... inputPipes)
        Constructor
        Parameters:
        comparator - The total order relation to use when merging the data from the different input pipes. Should be consistent with the ordering of the input pipes. IMPORTANT NOTE: comparator must be consistent with equals: a.equals(b) if and only if comparator.compare(a,b)==0.
        inputPipes - The input pipes. Each of them must be sorted by the order defined in the provided comparator, and items may have duplicates.
    • Method Detail

      • shouldOutput

        protected boolean shouldOutput​(T item,
                                       BitSet pipesSeen)
        Description copied from class: MultiSortedBasePipe
        The method to override for determining whether a visited value should be part of the output or not
        Specified by:
        shouldOutput in class MultiSortedBasePipe<T>
        Parameters:
        item - The item
        pipesSeen - A bitset specifying the different input pipes in which the item is found. Index #i corresponds to pipe #i in the pipes list provided in the ctor. Note that it is guaranteed that at least one bit is turned on.
        Returns:
        true for outputting this item, false for skipping
      • canTerminate

        protected boolean canTerminate​(BitSet activePipes)
        Description copied from class: MultiSortedBasePipe
        Called whenever one of the input pipes terminated. Allows implementations to decide whether to exit early if this there's no point in continuing with the remaining active pipes.
        Specified by:
        canTerminate in class MultiSortedBasePipe<T>
        Parameters:
        activePipes - A bitset describing the currently active pipes. Index #i corresponds to pipe #i in the pipes list provided in the ctor.
        Returns:
        true for terminating the output, false for continuing.
      • getProgress

        public float getProgress()
        Returns:
        The pipe flow progress, as a floating number between 0.0 and 1.0. Important implementation rules: 1) Calling this method before start() call is complete isn't allowed and has an undefined behavior. 2) Implementation should do best effort to provide an estimate of the progress this pipe has made (0.0 - 1.0) 3) When the pipe is fully consumed, getProgress() should return 1.0. 4) Results must be monotonous, i.e. results of consecutive calls may never be decreasing. 5) Thread safety: progress may be maintained by some thread/s but monitoring by other threads. Implementations must be thread safe.