Class ItemsSketchSortedView<T>
- java.lang.Object
-
- org.apache.datasketches.quantilescommon.ItemsSketchSortedView<T>
-
- Type Parameters:
T- The sketch data type
- All Implemented Interfaces:
GenericSortedView<T>,PartitioningFeature<T>,SketchPartitionLimits,SortedView
public class ItemsSketchSortedView<T> extends Object implements GenericSortedView<T>
The SortedView for the KllItemsSketch and the classic ItemsSketch.- Author:
- Alexander Saydakov, Lee Rhodes
-
-
Constructor Summary
Constructors Constructor Description ItemsSketchSortedView(T[] quantiles, long[] cumWeights, QuantilesGenericAPI<T> sk)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Comparator<? super T>getComparator()Gets the Comparator for this generic type.long[]getCumulativeWeights()Returns the array of cumulative weights from the sketch.TgetMaxItem()Returns the maximum item of the stream.intgetMaxPartitions()Gets the maximum number of partitions this sketch will support based on the configured size K and the number of retained values of this sketch.TgetMinItem()Returns the minimum item of the stream.longgetN()Gets the length of the input stream offered to the sketch..intgetNumRetained()Gets the number of quantiles retained by this sorted view.GenericPartitionBoundaries<T>getPartitionBoundariesFromNumParts(int numEquallySizedParts, QuantileSearchCriteria searchCrit)This method returns an instance ofGenericPartitionBoundarieswhich provides sufficient information for the user to create the given number of equally sized partitions, where "equally sized" refers to an approximately equal number of items per partition.GenericPartitionBoundaries<T>getPartitionBoundariesFromPartSize(long nominalPartitionSize, QuantileSearchCriteria searchCrit)This method returns an instance ofGenericPartitionBoundarieswhich provides sufficient information for the user to create the given number of equally sized partitions, where "equally sized" refers to an approximately equal number of items per partition.TgetQuantile(double rank, QuantileSearchCriteria searchCrit)Gets the approximate quantile of the given normalized rank and the given search criterion.T[]getQuantiles()Returns the full array of quantiles.T[]getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit)Gets an array of quantiles corresponding to the given array of ranks.doublegetRank(T quantile, QuantileSearchCriteria searchCrit)Gets the normalized rank corresponding to the given a quantile.booleanisEmpty()Returns true if this sorted view is empty.GenericSortedViewIterator<T>iterator()Returns an iterator for this Sorted View.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.datasketches.quantilescommon.GenericSortedView
getCDF, getPMF
-
Methods inherited from interface org.apache.datasketches.quantilescommon.PartitioningFeature
getPartitionBoundariesFromNumParts, getPartitionBoundariesFromPartSize
-
Methods inherited from interface org.apache.datasketches.quantilescommon.SketchPartitionLimits
getMinPartitionSizeItems
-
-
-
-
Constructor Detail
-
ItemsSketchSortedView
public ItemsSketchSortedView(T[] quantiles, long[] cumWeights, QuantilesGenericAPI<T> sk)
Constructor.- Parameters:
quantiles- the given array of quantiles, which must be ordered.cumWeights- the given array of cumulative weights, which must be ordered, start with the value one, and the last value must be equal to N, the total number of items updated to the sketch.sk- the underlying quantile sketch.
-
-
Method Detail
-
getComparator
public Comparator<? super T> getComparator()
Description copied from interface:GenericSortedViewGets the Comparator for this generic type.- Specified by:
getComparatorin interfaceGenericSortedView<T>- Returns:
- the Comparator for this generic type.
-
getCumulativeWeights
public long[] getCumulativeWeights()
Description copied from interface:SortedViewReturns the array of cumulative weights from the sketch. Also known as the natural ranks, which are the Natural Numbers on the interval [1, N].- Specified by:
getCumulativeWeightsin interfaceSortedView- Returns:
- the array of cumulative weights (or natural ranks).
-
getMaxItem
public T getMaxItem()
Description copied from interface:GenericSortedViewReturns the maximum item of the stream. This may be distinct from the largest item retained by the sketch algorithm.- Specified by:
getMaxItemin interfaceGenericSortedView<T>- Returns:
- the maximum item of the stream
-
getMinItem
public T getMinItem()
Description copied from interface:GenericSortedViewReturns the minimum item of the stream. This may be distinct from the smallest item retained by the sketch algorithm.- Specified by:
getMinItemin interfaceGenericSortedView<T>- Returns:
- the minimum item of the stream
-
getN
public long getN()
Description copied from interface:SketchPartitionLimitsGets the length of the input stream offered to the sketch..- Specified by:
getNin interfaceSketchPartitionLimits- Specified by:
getNin interfaceSortedView- Returns:
- the length of the input stream offered to the sketch.
-
getNumRetained
public int getNumRetained()
Description copied from interface:SortedViewGets the number of quantiles retained by this sorted view. This may be slightly different from the function with the same name when called from the originating sketch.- Specified by:
getNumRetainedin interfaceSortedView- Returns:
- the number of quantiles retained by this sorted view
-
getMaxPartitions
public int getMaxPartitions()
Description copied from interface:SketchPartitionLimitsGets the maximum number of partitions this sketch will support based on the configured size K and the number of retained values of this sketch.- Specified by:
getMaxPartitionsin interfaceSketchPartitionLimits- Returns:
- the maximum number of partitions this sketch will support.
-
getPartitionBoundariesFromPartSize
public GenericPartitionBoundaries<T> getPartitionBoundariesFromPartSize(long nominalPartitionSize, QuantileSearchCriteria searchCrit)
Description copied from interface:PartitioningFeatureThis method returns an instance ofGenericPartitionBoundarieswhich provides sufficient information for the user to create the given number of equally sized partitions, where "equally sized" refers to an approximately equal number of items per partition.The sketch must not be empty.
- Specified by:
getPartitionBoundariesFromPartSizein interfacePartitioningFeature<T>- Parameters:
nominalPartitionSize- an integer that specifies the nominal size, in items, of each target partition. This must be a positive integer greater thangetMinPartitionSizeItems().searchCrit- If INCLUSIVE, all the returned quantiles are the upper boundaries of the equally sized partitions with the exception of the lowest returned quantile, which is the lowest boundary of the lowest ranked partition. If EXCLUSIVE, all the returned quantiles are the lower boundaries of the equally sized partitions with the exception of the highest returned quantile, which is the upper boundary of the highest ranked partition.- Returns:
- an instance of
GenericPartitionBoundaries.
-
getPartitionBoundariesFromNumParts
public GenericPartitionBoundaries<T> getPartitionBoundariesFromNumParts(int numEquallySizedParts, QuantileSearchCriteria searchCrit)
Description copied from interface:PartitioningFeatureThis method returns an instance ofGenericPartitionBoundarieswhich provides sufficient information for the user to create the given number of equally sized partitions, where "equally sized" refers to an approximately equal number of items per partition.The sketch must not be empty.
- Specified by:
getPartitionBoundariesFromNumPartsin interfacePartitioningFeature<T>- Parameters:
numEquallySizedParts- an integer that specifies the number of equally sized partitions betweengetMinItem()andgetMaxItem(). This must be a positive integer less thangetMaxPartitions()- A 1 will return: minItem, maxItem.
- A 2 will return: minItem, median quantile, maxItem.
- Etc.
searchCrit- If INCLUSIVE, all the returned quantiles are the upper boundaries of the equally sized partitions with the exception of the lowest returned quantile, which is the lowest boundary of the lowest ranked partition. If EXCLUSIVE, all the returned quantiles are the lower boundaries of the equally sized partitions with the exception of the highest returned quantile, which is the upper boundary of the highest ranked partition.- Returns:
- an instance of
GenericPartitionBoundaries.
-
getQuantile
public T getQuantile(double rank, QuantileSearchCriteria searchCrit)
Description copied from interface:GenericSortedViewGets the approximate quantile of the given normalized rank and the given search criterion.- Specified by:
getQuantilein interfaceGenericSortedView<T>- Parameters:
rank- the given normalized rank, a double in the range [0.0, 1.0].searchCrit- If INCLUSIVE, the given rank includes all quantiles ≤ the quantile directly corresponding to the given rank. If EXCLUSIVE, he given rank includes all quantiles < the quantile directly corresponding to the given rank.- Returns:
- the approximate quantile given the normalized rank.
- See Also:
QuantileSearchCriteria
-
getQuantiles
public T[] getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit)
Gets an array of quantiles corresponding to the given array of ranks.- Parameters:
ranks- the given array of normalized rankssearchCrit- The search criterion: either INCLUSIVE or EXCLUSIVE.- Returns:
- an array of quantiles corresponding to the given array of ranks.
-
getQuantiles
public T[] getQuantiles()
Description copied from interface:GenericSortedViewReturns the full array of quantiles.- Specified by:
getQuantilesin interfaceGenericSortedView<T>- Returns:
- the full array of quantiles.
-
getRank
public double getRank(T quantile, QuantileSearchCriteria searchCrit)
Description copied from interface:GenericSortedViewGets the normalized rank corresponding to the given a quantile.- Specified by:
getRankin interfaceGenericSortedView<T>- Parameters:
quantile- the given quantilesearchCrit- if INCLUSIVE the given quantile is included into the rank.- Returns:
- the normalized rank corresponding to the given quantile.
- See Also:
QuantileSearchCriteria
-
isEmpty
public boolean isEmpty()
Description copied from interface:SortedViewReturns true if this sorted view is empty.- Specified by:
isEmptyin interfaceSortedView- Returns:
- true if this sorted view is empty.
-
iterator
public GenericSortedViewIterator<T> iterator()
Description copied from interface:SortedViewReturns an iterator for this Sorted View.- Specified by:
iteratorin interfaceGenericSortedView<T>- Specified by:
iteratorin interfaceSortedView- Returns:
- an iterator for this Sorted View.
-
-