25
25
import static org .apache .datasketches .kll .KllSketch .SketchStructure .COMPACT_EMPTY ;
26
26
import static org .apache .datasketches .kll .KllSketch .SketchStructure .COMPACT_FULL ;
27
27
import static org .apache .datasketches .kll .KllSketch .SketchStructure .COMPACT_SINGLE ;
28
+ import static org .apache .datasketches .kll .KllSketch .SketchStructure .UPDATABLE ;
28
29
29
30
import java .lang .reflect .Array ;
30
31
import java .util .Comparator ;
34
35
import org .apache .datasketches .memory .Memory ;
35
36
import org .apache .datasketches .memory .WritableMemory ;
36
37
38
+ /**
39
+ * This class implements an on-heap doubles KllSketch.
40
+ *
41
+ * <p>Please refer to the documentation in the package-info:<br>
42
+ * {@link org.apache.datasketches.kll}</p>
43
+ *
44
+ * @author Lee Rhodes, Kevin Lang
45
+ */
37
46
@ SuppressWarnings ("unchecked" )
38
47
final class KllHeapItemsSketch <T > extends KllItemsSketch <T > {
39
48
private final int k ; // configured size of K.
@@ -46,14 +55,17 @@ final class KllHeapItemsSketch<T> extends KllItemsSketch<T> {
46
55
private Object [] itemsArr ;
47
56
48
57
/**
49
- * Constructs a new empty instance of this sketch on the Java heap.
58
+ * New instance heap constructor.
59
+ * @param k parameter that controls size of the sketch and accuracy of estimates.
60
+ * @param m parameter controls the minimum level width in items. It can be 2, 4, 6 or 8.
61
+ * The DEFAULT_M, which is 8 is recommended. Other sizes of <em>m</em> should be considered
62
+ * experimental as they have not been as well characterized.
63
+ * @param comparator user specified comparator of type T.
64
+ * @param serDe serialization / deserialization class
50
65
*/
51
- KllHeapItemsSketch (
52
- final int k ,
53
- final int m ,
54
- final Comparator <? super T > comparator ,
66
+ KllHeapItemsSketch (final int k , final int m , final Comparator <? super T > comparator ,
55
67
final ArrayOfItemsSerDe <T > serDe ) {
56
- super (SketchStructure . UPDATABLE , comparator , serDe );
68
+ super (UPDATABLE , comparator , serDe );
57
69
KllHelper .checkM (m );
58
70
KllHelper .checkK (k , m );
59
71
this .levelsArr = new int [] {k , k };
@@ -69,11 +81,27 @@ final class KllHeapItemsSketch<T> extends KllItemsSketch<T> {
69
81
}
70
82
71
83
/**
72
- * The Heapify constructor, which constructs an image of this sketch from
73
- * a Memory (or WritableMemory) object that was created by this sketch
74
- * and has a type T consistent with the given comparator and serDe.
75
- * Once the data from the given Memory has been transferred into this heap sketch,
76
- * the reference to the Memory object is no longer retained.
84
+ * Used for creating a temporary sketch for use with weighted updates.
85
+ */
86
+ KllHeapItemsSketch (final int k , final int m , final T item , final long weight , final Comparator <? super T > comparator ,
87
+ final ArrayOfItemsSerDe <T > serDe ) {
88
+ super (UPDATABLE , comparator , serDe );
89
+ KllHelper .checkM (m );
90
+ KllHelper .checkK (k , m );
91
+ this .levelsArr = KllHelper .createLevelsArray (weight );
92
+ this .readOnly = false ;
93
+ this .k = k ;
94
+ this .m = m ;
95
+ this .n = weight ;
96
+ this .minK = k ;
97
+ this .isLevelZeroSorted = false ;
98
+ this .minItem = item ;
99
+ this .maxItem = item ;
100
+ this .itemsArr = KllItemsHelper .createItemsArray (serDe .getClassOfT (), item , weight );
101
+ }
102
+
103
+ /**
104
+ * The Heapify constructor
77
105
* @param srcMem the Source Memory image that contains data.
78
106
* @param comparator the comparator for this sketch and given Memory.
79
107
* @param serDe the serializer / deserializer for this sketch and the given Memory.
0 commit comments