Class QuantilesItemsUnion<T>
java.lang.Object
org.apache.datasketches.quantiles.QuantilesItemsUnion<T>
- Type Parameters:
T- The sketch item data type.
The API for Union operations for generic QuantilesItemsSketches
- Author:
- Lee Rhodes, Alexander Saydakov
-
Method Summary
Modifier and TypeMethodDescriptionintReturns the effective k of this Union.static <T> QuantilesItemsUnion<T> getInstance(Class<T> clazz, int maxK, Comparator<? super T> comparator) Create an instance of QuantilesItemsUnionstatic <T> QuantilesItemsUnion<T> getInstance(Class<T> clazz, Comparator<? super T> comparator) Create an instance of QuantilesItemsUnion with the default k.intgetMaxK()Returns the configured maxK of this Union.Gets the result of this Union operation as a copy of the internal state.Gets the sketch result of this Union operation and resets this Union to the virgin state.static <T> QuantilesItemsUnion<T> initialize(QuantilesItemsSketch<T> sketch) Initialize a new QuantilesItemsUnion with an instance of QuantilesItemsSketchstatic <T> QuantilesItemsUnion<T> initializeWithMemorySegment(Class<T> clazz, MemorySegment srcSeg, Comparator<? super T> comparator, ArrayOfItemsSerDe<T> serDe) Initialize a new QuantilesItemsUnion with a heapified instance of an QuantilesItemsSketch from a MemorySegment.booleanisEmpty()Returns true if this union is emptyvoidreset()Resets this Union to a virgin state.byte[]toByteArray(ArrayOfItemsSerDe<T> serDe) Serialize this union to a byte array.toString()Returns summary information about the backing sketch.toString(boolean sketchSummary, boolean dataDetail) Returns summary information about the backing sketch.voidunion(MemorySegment srcSeg, ArrayOfItemsSerDe<T> serDe) Iterative union operation, which means this method can be repeatedly called.voidunion(QuantilesItemsSketch<T> sketchIn) Iterative union operation, which means this method can be repeatedly called.voidUpdate this union with the given dataItem.
-
Method Details
-
getInstance
public static <T> QuantilesItemsUnion<T> getInstance(Class<T> clazz, Comparator<? super T> comparator) Create an instance of QuantilesItemsUnion with the default k.- Type Parameters:
T- The sketch item data type.- Parameters:
clazz- The sketch class type.comparator- to compare items.- Returns:
- a new instance of QuantilesItemsUnion
-
getInstance
public static <T> QuantilesItemsUnion<T> getInstance(Class<T> clazz, int maxK, Comparator<? super T> comparator) Create an instance of QuantilesItemsUnion- Type Parameters:
T- The sketch item data type.- Parameters:
clazz- The sketch class type.maxK- determines the accuracy and size of the union and is a maximum. The effective k can be smaller due to unions with smaller k sketches. maxK must be a power of 2 to enable unioning of sketches with a different k.comparator- to compare items.- Returns:
- an new instance of QuantilesItemsUnion
-
initializeWithMemorySegment
public static <T> QuantilesItemsUnion<T> initializeWithMemorySegment(Class<T> clazz, MemorySegment srcSeg, Comparator<? super T> comparator, ArrayOfItemsSerDe<T> serDe) Initialize a new QuantilesItemsUnion with a heapified instance of an QuantilesItemsSketch from a MemorySegment.- Type Parameters:
T- The sketch data type.- Parameters:
clazz- The sketch class type.srcSeg- the given srcSeg, an image of an QuantilesItemsSketch. A reference to srcSeg will not be maintained internally.comparator- to compare items.serDe- an instance of ArrayOfItemsSerDe.- Returns:
- an QuantilesItemsUnion initialized with a heapified QuantilesItemsSketch from a MemorySegment.
-
initialize
Initialize a new QuantilesItemsUnion with an instance of QuantilesItemsSketch- Type Parameters:
T- The sketch data type- Parameters:
sketch- an instance of QuantilesItemsSketch to initialize this union- Returns:
- an initialized instance of QuantilesItemsUnion
-
union
Iterative union operation, which means this method can be repeatedly called. Merges the given sketch into this union object. The given sketch is not modified. It is required that the ratio of the two K's be a power of 2. This is easily satisfied if each of the K's are already a power of 2. If the given sketch is null or empty it is ignored.It is required that the results of the union operation, which can be obtained at any time, is obtained from
getResult().- Parameters:
sketchIn- the sketch to be merged into this one.
-
union
Iterative union operation, which means this method can be repeatedly called. Merges the given MemorySegment image of a QuantilesItemsSketch into this union object. The given MemorySegment object is not modified and a link to it is not retained. It is required that the ratio of the two K's be a power of 2. This is easily satisfied if each of the K's are already a power of 2. If the given sketch is null or empty it is ignored.It is required that the results of the union operation, which can be obtained at any time, is obtained from
getResult().- Parameters:
srcSeg- MemorySegment image of sketch to be mergedserDe- an instance of ArrayOfItemsSerDe
-
update
Update this union with the given dataItem.- Parameters:
dataItem- The given datum.
-
getResult
Gets the result of this Union operation as a copy of the internal state. This enables further union update operations on this state.- Returns:
- the result of this Union operation
-
getResultAndReset
Gets the sketch result of this Union operation and resets this Union to the virgin state.- Returns:
- the result of this Union operation and reset.
-
reset
public void reset()Resets this Union to a virgin state. Keeps maxK, comparator and clazz -
isEmpty
public boolean isEmpty()Returns true if this union is empty- Returns:
- true if this union is empty
-
getMaxK
public int getMaxK()Returns the configured maxK of this Union.- Returns:
- the configured maxK of this Union.
-
getEffectiveK
public int getEffectiveK()Returns the effective k of this Union.- Returns:
- the effective k of this Union.
-
toString
-
toString
Returns summary information about the backing sketch. Used for debugging.- Parameters:
sketchSummary- if true includes sketch summarydataDetail- if true includes data detail- Returns:
- summary information about the sketch.
-
toByteArray
Serialize this union to a byte array. Result is an QuantilesItemsSketch, serialized in an unordered, non-compact form. The resulting byte[] can be passed to getInstance for either a sketch or union.- Parameters:
serDe- an instance of ArrayOfItemsSerDe- Returns:
- byte array of this union
-