Package org.pipecraft.pipes.sync.inter
Class SortedSubtractionPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.sync.inter.MultiSortedBasePipe<T>
-
- org.pipecraft.pipes.sync.inter.SortedSubtractionPipe<T>
-
- Type Parameters:
T- The data type of the items this pipe works with
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<T>
public class SortedSubtractionPipe<T> extends MultiSortedBasePipe<T>
An intermediate pipe performing a set subtraction operation on two given pipes (i.e. returns items from pipe A which aren't found in pipe B). 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 Summary
Constructors Constructor Description SortedSubtractionPipe(Pipe<T> pipeA, Pipe<T> pipeB, Comparator<? super T> comparator)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanTerminate(BitSet activePipes)Called whenever one of the input pipes terminated.floatgetProgress()protected booleanshouldOutput(T item, BitSet pipesSeen)The method to override for determining whether a visited value should be part of the output or not-
Methods inherited from class org.pipecraft.pipes.sync.inter.MultiSortedBasePipe
close, getInputPipes, next, peek, start
-
-
-
-
Constructor Detail
-
SortedSubtractionPipe
public SortedSubtractionPipe(Pipe<T> pipeA, Pipe<T> pipeB, Comparator<? super T> comparator)
Constructor- Parameters:
pipeA- left side pipe (The pipe we are subtracting from)pipeB- right side pipecomparator- 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.
-
-
Method Detail
-
shouldOutput
protected boolean shouldOutput(T item, BitSet pipesSeen)
Description copied from class:MultiSortedBasePipeThe method to override for determining whether a visited value should be part of the output or not- Specified by:
shouldOutputin classMultiSortedBasePipe<T>- Parameters:
item- The itempipesSeen- 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:MultiSortedBasePipeCalled 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:
canTerminatein classMultiSortedBasePipe<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.
-
-