smile.sort
Class HeapSelect<T extends java.lang.Comparable<? super T>>
- java.lang.Object
-
- smile.sort.HeapSelect<T>
-
public class HeapSelect<T extends java.lang.Comparable<? super T>> extends java.lang.ObjectThis class tracks the smallest values seen thus far in a stream of values. This implements a single-pass selection for large data sets. That is, we have a stream of input values, each of which we get to see only once. We want to be able to report at any time, say after n values, the i-th smallest value see so far.
-
-
Constructor Summary
Constructors Constructor and Description HeapSelect(T[] heap)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(T datum)Assimilate a new value from the stream.Tget(int i)Returns the i-th smallest value seen so far.voidheapify()In case of avoiding creating new objects frequently, one may check and update the peek object directly and call this method to sort the internal array in heap order.Tpeek()Returns the k-th smallest value seen so far.voidsort()Sort the smallest values.
-
-
-
Constructor Detail
-
HeapSelect
public HeapSelect(T[] heap)
Constructor.- Parameters:
heap- the array to store smallest values to track.
-
-
Method Detail
-
add
public void add(T datum)
Assimilate a new value from the stream.
-
heapify
public void heapify()
In case of avoiding creating new objects frequently, one may check and update the peek object directly and call this method to sort the internal array in heap order.
-
peek
public T peek()
Returns the k-th smallest value seen so far.
-
get
public T get(int i)
Returns the i-th smallest value seen so far. i = 0 returns the smallest value seen, i = 1 the second largest, ..., i = k-1 the last position tracked. Also, i must be less than the number of previous assimilated.
-
sort
public void sort()
Sort the smallest values.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG