Class PercentilePipe<T,​C extends Comparable<C>>

  • Type Parameters:
    T - The input items type
    C - The type of the sorting component. Must be comparable and must be suitable for hash keys.
    All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe

    public class PercentilePipe<T,​C extends Comparable<C>>
    extends TerminalPipe
    A terminal pipe that finds a given percentile p in the input pipe. Each item is mapped to a 'sorting component', specifying the metric by which the order is defined. This implementation uses O(K) memory, where k is the number of unique sorting-component values. Therefore, it's not safe to use this pipe when K is large, but very efficient when K items can be stored in memory.
    Author:
    Eyal Schneider
    • Constructor Detail

      • PercentilePipe

        public PercentilePipe​(Pipe<T> input,
                              double p,
                              Function<T,​C> sortingComponentExtractor)
        Constructor
        Parameters:
        input - The input pipe
        p - The required percentile. Must be between 0.0 and 1.0.
        sortingComponentExtractor - Extracts the sorting component from input items. Must not return null. The sorting component but be suitable for hash keys!
    • Method Detail

      • start

        public void start()
                   throws PipeException,
                          InterruptedException
        Description copied from interface: BasePipe
        Performs pre-processing prior to item flow throw the pipe. Implementations must call the same method for all their input pipes before accessing their items. This is typically done here.
        Throws:
        PipeException - In case of pipe errors in this pipe or somewhere up-stream.
        InterruptedException - In case that the operation has been interrupted by another thread.
      • getPercentileValue

        public C getPercentileValue()
        Returns:
        The required percentile value, or null if the input is empty. Call this method after start() completes running.