Class KthSelector

  • All Implemented Interfaces:
    java.io.Serializable

    public class KthSelector
    extends java.lang.Object
    implements java.io.Serializable
    A Simple Kth selector implementation to pick up the Kth ordered element from a work array containing the input numbers.
    Since:
    3.4
    See Also:
    Serialized Form
    • Method Detail

      • getPivotingStrategy

        public PivotingStrategyInterface getPivotingStrategy()
        Get the pivotin strategy.
        Returns:
        pivoting strategy
      • select

        public double select​(double[] work,
                             int[] pivotsHeap,
                             int k)
        Select Kth value in the array.
        Parameters:
        work - work array to use to find out the Kth value
        pivotsHeap - cached pivots heap that can be used for efficient estimation
        k - the index whose value in the array is of interest
        Returns:
        Kth value
      • partition

        private int partition​(double[] work,
                              int begin,
                              int end,
                              int pivot)
        Partition an array slice around a pivot.Partitioning exchanges array elements such that all elements smaller than pivot are before it and all elements larger than pivot are after it.
        Parameters:
        work - work array
        begin - index of the first element of the slice of work array
        end - index after the last element of the slice of work array
        pivot - initial index of the pivot
        Returns:
        index of the pivot after partition