• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / datasketches-java / #306

30 Apr 2024 10:01PM UTC coverage: 97.645% (-0.5%) from 98.139%
#306

push

web-flow
Merge pull request #555 from apache/fix_pom_xml_header

Fix pom xml header

26865 of 27513 relevant lines covered (97.64%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.8
/src/main/java/org/apache/datasketches/hll/HllSketch.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.datasketches.hll;
21

22
import static org.apache.datasketches.common.Util.LS;
23
import static org.apache.datasketches.common.Util.checkBounds;
24
import static org.apache.datasketches.hll.HllUtil.EMPTY;
25
import static org.apache.datasketches.hll.HllUtil.KEY_BITS_26;
26
import static org.apache.datasketches.hll.HllUtil.LG_AUX_ARR_INTS;
27
import static org.apache.datasketches.hll.HllUtil.checkPreamble;
28
import static org.apache.datasketches.hll.PreambleUtil.HLL_BYTE_ARR_START;
29
import static org.apache.datasketches.hll.PreambleUtil.extractCompactFlag;
30
import static org.apache.datasketches.hll.PreambleUtil.extractLgK;
31
import static org.apache.datasketches.hll.PreambleUtil.extractTgtHllType;
32

33
import java.util.Objects;
34

35
import org.apache.datasketches.common.SketchesArgumentException;
36
import org.apache.datasketches.memory.Memory;
37
import org.apache.datasketches.memory.WritableMemory;
38

39
/**
40
 * The HllSketch is actually a collection of compact implementations of Phillipe Flajolet’s HyperLogLog (HLL)
41
 * sketch but with significantly improved error behavior and excellent speed performance.
42
 *
43
 * <p>If the use case for sketching is primarily counting uniques and merging, the HLL sketch is the 2nd highest
44
 * performing in terms of accuracy for storage space consumed in the DataSketches library
45
 * (the new CPC sketch developed by Kevin J. Lang now beats HLL in terms of accuracy / space).
46
 * For large counts, HLL sketches can be 2 to 8 times smaller for the same accuracy than the DataSketches Theta
47
 * Sketches when serialized, but the Theta sketches can do set intersections and differences while HLL and CPC cannot.
48
 * The CPC sketch and HLL share similar use cases, but the CPC sketch is about 30 to 40% smaller than the HLL sketch
49
 * when serialized and larger than the HLL when active in memory.  Choose your weapons!</p>
50
 *
51
 * <p>A new HLL sketch is created with a simple constructor:</p>
52
 * <pre>{@code
53
 * int lgK = 12; //This is log-base2 of k, so k = 4096. lgK can be from 4 to 21
54
 * HllSketch sketch = new HllSketch(lgK); //TgtHllType.HLL_4 is the default
55
 * //OR
56
 * HllSketch sketch = new HllSketch(lgK, TgtHllType.HLL_6);
57
 * //OR
58
 * HllSketch sketch = new HllSketch(lgK, TgtHllType.HLL_8);
59
 * }</pre>
60
 *
61
 * <p>All three different sketch types are targets in that the sketches start out in a warm-up mode that is small in
62
 * size and gradually grows as needed until the full HLL array is allocated. The HLL_4, HLL_6 and HLL_8 represent
63
 * different levels of compression of the final HLL array where the 4, 6 and 8 refer to the number of bits each
64
 * bucket of the HLL array is compressed down to.
65
 * The HLL_4 is the most compressed but generally slower than the other two, especially during union operations.</p>
66
 *
67
 * <p>All three types share the same API. Updating the HllSketch is very simple:</p>
68
 *
69
 * <pre>{@code
70
 * long n = 1000000;
71
 * for (int i = 0; i < n; i++) {
72
 *   sketch.update(i);
73
 * }
74
 * }</pre>
75
 *
76
 * <p>Each of the presented integers above are first hashed into 128-bit hash values that are used by the sketch
77
 * HLL algorithm, so the above loop is essentially equivalent to using a random number generator initialized with a
78
 * seed so that the sequence is deterministic and random.</p>
79
 *
80
 * <p>Obtaining the cardinality results from the sketch is also simple:</p>
81
 *
82
 * <pre>{@code
83
 * double estimate = sketch.getEstimate();
84
 * double estUB = sketch.getUpperBound(1.0); //the upper bound at 1 standard deviation.
85
 * double estLB = sketch.getLowerBound(1.0); //the lower bound at 1 standard deviation.
86
 * //OR
87
 * System.out.println(sketch.toString()); //will output a summary of the sketch.
88
 * }</pre>
89
 *
90
 * <p>Which produces a console output something like this:</p>
91
 *
92
 * <pre>{@code
93
 * ### HLL SKETCH SUMMARY:
94
 *   Log Config K   : 12
95
 *   Hll Target     : HLL_4
96
 *   Current Mode   : HLL
97
 *   LB             : 977348.7024560181
98
 *   Estimate       : 990116.6007366662
99
 *   UB             : 1003222.5095308956
100
 *   OutOfOrder Flag: false
101
 *   CurMin         : 5
102
 *   NumAtCurMin    : 1
103
 *   HipAccum       : 990116.6007366662
104
 * }</pre>
105
 *
106
 * @author Lee Rhodes
107
 * @author Kevin Lang
108
 */
109
public class HllSketch extends BaseHllSketch {
110

111
  /**
112
   * The default Log_base2 of K
113
   */
114
  public static final int DEFAULT_LG_K = 12;
115

116
  /**
117
   * The default HLL-TYPE is HLL_4
118
   */
119
  public static final TgtHllType DEFAULT_HLL_TYPE = TgtHllType.HLL_4;
1✔
120

121
  HllSketchImpl hllSketchImpl = null;
1✔
122

123
  /**
124
   * Constructs a new on-heap sketch with the default lgConfigK and tgtHllType.
125
   */
126
  public HllSketch() {
127
    this(DEFAULT_LG_K, DEFAULT_HLL_TYPE);
1✔
128
  }
1✔
129

130
  /**
131
   * Constructs a new on-heap sketch with the default tgtHllType.
132
   * @param lgConfigK The Log2 of K for the target HLL sketch. This value must be
133
   * between 4 and 21 inclusively.
134
   */
135
  public HllSketch(final int lgConfigK) {
136
    this(lgConfigK, DEFAULT_HLL_TYPE);
1✔
137
  }
1✔
138

139
  /**
140
   * Constructs a new on-heap sketch with the type of HLL sketch to configure.
141
   * @param lgConfigK The Log2 of K for the target HLL sketch. This value must be
142
   * between 4 and 21 inclusively.
143
   * @param tgtHllType the desired HLL type.
144
   */
145
  public HllSketch(final int lgConfigK, final TgtHllType tgtHllType) {
1✔
146
    hllSketchImpl = new CouponList(HllUtil.checkLgK(lgConfigK), tgtHllType, CurMode.LIST);
1✔
147
  }
1✔
148

149
  /**
150
   * Constructs a new sketch with the type of HLL sketch to configure and the given
151
   * WritableMemory as the destination for the sketch. This WritableMemory is usually configured
152
   * for off-heap memory. What remains on the java heap is a thin wrapper object that reads and
153
   * writes to the given WritableMemory.
154
   *
155
   * <p>The given <i>dstMem</i> is checked for the required capacity as determined by
156
   * {@link #getMaxUpdatableSerializationBytes(int, TgtHllType)}.
157
   * @param lgConfigK The Log2 of K for the target HLL sketch. This value must be
158
   * between 4 and 21 inclusively.
159
   * @param tgtHllType the desired HLL type.
160
   * @param dstMem the destination memory for the sketch.
161
   */
162
  public HllSketch(final int lgConfigK, final TgtHllType tgtHllType, final WritableMemory dstMem) {
1✔
163
    Objects.requireNonNull(dstMem, "Destination Memory must not be null");
1✔
164
    final long minBytes = getMaxUpdatableSerializationBytes(lgConfigK, tgtHllType);
1✔
165
    final long capBytes = dstMem.getCapacity();
1✔
166
    HllUtil.checkMemSize(minBytes, capBytes);
1✔
167
    dstMem.clear(0, minBytes);
1✔
168
    hllSketchImpl = DirectCouponList.newInstance(lgConfigK, tgtHllType, dstMem);
1✔
169
  }
1✔
170

171
  /**
172
   * Copy constructor used by copy().
173
   * @param that another HllSketch
174
   */
175
  HllSketch(final HllSketch that) {
1✔
176
    hllSketchImpl = that.hllSketchImpl.copy();
1✔
177
  }
1✔
178

179
  /**
180
   * Special constructor used by copyAs, heapify
181
   * @param that another HllSketchImpl, which must already be a copy
182
   */
183
  HllSketch(final HllSketchImpl that) {
1✔
184
    hllSketchImpl = that;
1✔
185
  }
1✔
186

187
  /**
188
   * Heapify the given byte array, which must be a valid HllSketch image and may have data.
189
   * @param byteArray the given byte array.  This byteArray is not modified and is not retained
190
   * by the on-heap sketch.
191
   * @return an HllSketch on the java heap.
192
   */
193
  public static final HllSketch heapify(final byte[] byteArray) {
194
    return heapify(Memory.wrap(byteArray));
1✔
195
  }
196

197
  /**
198
   * Heapify the given Memory, which must be a valid HllSketch image and may have data.
199
   * @param srcMem the given Memory, which is read-only.
200
   * @return an HllSketch on the java heap.
201
   */
202
  public static final HllSketch heapify(final Memory srcMem) {
203
    return heapify(srcMem, true);
1✔
204
  }
205

206
  //used by union and above
207
  static final HllSketch heapify(final Memory srcMem, final boolean checkRebuild) {
208
    Objects.requireNonNull(srcMem, "Source Memory must not be null");
1✔
209
    checkBounds(0, 8, srcMem.getCapacity()); //need min 8 bytes
1✔
210
    final CurMode curMode = checkPreamble(srcMem);
1✔
211
    final HllSketch heapSketch;
212
    if (curMode == CurMode.HLL) {
1✔
213
      final TgtHllType tgtHllType = extractTgtHllType(srcMem);
1✔
214
      if (tgtHllType == TgtHllType.HLL_4) {
1✔
215
        heapSketch = new HllSketch(Hll4Array.heapify(srcMem));
1✔
216
      } else if (tgtHllType == TgtHllType.HLL_6) {
1✔
217
        heapSketch = new HllSketch(Hll6Array.heapify(srcMem));
1✔
218
      } else { //Hll_8
219
        heapSketch = new HllSketch(Hll8Array.heapify(srcMem));
1✔
220
        if (checkRebuild) {
1✔
221
          Union.checkRebuildCurMinNumKxQ(heapSketch);
1✔
222
        }
223
      }
224
    } else if (curMode == CurMode.LIST) {
1✔
225
      heapSketch = new HllSketch(CouponList.heapifyList(srcMem));
1✔
226
    } else {
227
      heapSketch = new HllSketch(CouponHashSet.heapifySet(srcMem));
1✔
228
    }
229
    return heapSketch;
1✔
230
  }
231

232
  /**
233
   * Wraps the given WritableMemory, which must be a image of a valid updatable sketch,
234
   * and may have data. What remains on the java heap is a
235
   * thin wrapper object that reads and writes to the given WritableMemory, which, depending on
236
   * how the user configures the WritableMemory, may actually reside on the Java heap or off-heap.
237
   *
238
   * <p>The given <i>dstMem</i> is checked for the required capacity as determined by
239
   * {@link #getMaxUpdatableSerializationBytes(int, TgtHllType)}.
240
   * @param srcWmem an writable image of a valid source sketch with data.
241
   * @return an HllSketch where the sketch data is in the given dstMem.
242
   */
243
  public static final HllSketch writableWrap(final WritableMemory srcWmem) {
244
    return writableWrap(srcWmem, true);
1✔
245
  }
246

247
  //used by union and above
248
  static final HllSketch writableWrap( final WritableMemory srcWmem, final boolean checkRebuild) {
249
    Objects.requireNonNull(srcWmem, "Source Memory must not be null");
1✔
250
    checkBounds(0, 8, srcWmem.getCapacity()); //need min 8 bytes
1✔
251
    if (extractCompactFlag(srcWmem)) {
1✔
252
      throw new SketchesArgumentException(
1✔
253
          "Cannot perform a writableWrap of a writable sketch image that is in compact form. "
254
          + "Compact sketches are by definition immutable.");
255
    }
256
    final int lgConfigK = extractLgK(srcWmem);
1✔
257
    final TgtHllType tgtHllType = extractTgtHllType(srcWmem);
1✔
258
    final long minBytes = getMaxUpdatableSerializationBytes(lgConfigK, tgtHllType);
1✔
259
    final long capBytes = srcWmem.getCapacity();
1✔
260
    HllUtil.checkMemSize(minBytes, capBytes);
1✔
261
    final CurMode curMode = checkPreamble(srcWmem);
1✔
262
    final HllSketch directSketch;
263
    if (curMode == CurMode.HLL) {
1✔
264
      if (tgtHllType == TgtHllType.HLL_4) {
1✔
265
        directSketch = new HllSketch(new DirectHll4Array(lgConfigK, srcWmem));
1✔
266
      } else if (tgtHllType == TgtHllType.HLL_6) {
1✔
267
        directSketch = new HllSketch(new DirectHll6Array(lgConfigK, srcWmem));
1✔
268
      } else { //Hll_8
269
        directSketch = new HllSketch(new DirectHll8Array(lgConfigK, srcWmem));
1✔
270
        if (checkRebuild) { //union only uses HLL_8, we allow non-finalized from a union call.
1✔
271
          Union.checkRebuildCurMinNumKxQ(directSketch);
1✔
272
        }
273
      }
274
    } else if (curMode == CurMode.LIST) {
1✔
275
      directSketch =
1✔
276
          new HllSketch(new DirectCouponList(lgConfigK, tgtHllType, curMode, srcWmem));
277
    } else { //SET
278
      directSketch =
1✔
279
          new HllSketch(new DirectCouponHashSet(lgConfigK, tgtHllType, srcWmem));
280
    }
281
    return directSketch;
1✔
282
  }
283

284
  /**
285
   * Wraps the given read-only Memory that must be a image of a valid sketch,
286
   * which may be in compact or updatable form, and should have data. Any attempt to update the
287
   * given source Memory will throw an exception.
288
   * @param srcMem a read-only image of a valid source sketch.
289
   * @return an HllSketch, where the read-only data of the sketch is in the given srcMem.
290
   *
291
   */
292
  public static final HllSketch wrap(final Memory srcMem) {
293
    Objects.requireNonNull(srcMem, "Source Memory must not be null");
1✔
294
    checkBounds(0, 8, srcMem.getCapacity()); //need min 8 bytes
1✔
295
    final int lgConfigK = extractLgK(srcMem);
1✔
296
    final TgtHllType tgtHllType = extractTgtHllType(srcMem);
1✔
297

298
    final CurMode curMode = checkPreamble(srcMem);
1✔
299
    final HllSketch directSketch;
300
    if (curMode == CurMode.HLL) {
1✔
301
      if (tgtHllType == TgtHllType.HLL_4) {
1✔
302
        directSketch = new HllSketch(new DirectHll4Array(lgConfigK, srcMem));
1✔
303
      } else if (tgtHllType == TgtHllType.HLL_6) {
1✔
304
        directSketch = new HllSketch(new DirectHll6Array(lgConfigK, srcMem));
1✔
305
      } else { //Hll_8
306
        directSketch = new HllSketch(new DirectHll8Array(lgConfigK, srcMem));
1✔
307
        //rebuild if srcMem came from a union and was not finalized, rather than throw exception.
308
        Union.checkRebuildCurMinNumKxQ(directSketch);
1✔
309
      }
310
    } else if (curMode == CurMode.LIST) {
1✔
311
      directSketch =
1✔
312
          new HllSketch(new DirectCouponList(lgConfigK, tgtHllType, curMode, srcMem));
313
    } else { //SET
314
      directSketch =
1✔
315
          new HllSketch(new DirectCouponHashSet(lgConfigK, tgtHllType, srcMem));
316
    }
317
    return directSketch;
1✔
318
  }
319

320
  /**
321
   * Return a copy of this sketch onto the Java heap.
322
   * @return a copy of this sketch onto the Java heap.
323
   */
324
  public HllSketch copy() {
325
    return new HllSketch(this);
1✔
326
  }
327

328
  /**
329
   * Return a deep copy of this sketch onto the Java heap with the specified TgtHllType.
330
   * @param tgtHllType the TgtHllType enum
331
   * @return a deep copy of this sketch with the specified TgtHllType.
332
   */
333
  public HllSketch copyAs(final TgtHllType tgtHllType) {
334
    return new HllSketch(hllSketchImpl.copyAs(tgtHllType));
1✔
335
  }
336

337
  @Override
338
  public double getCompositeEstimate() {
339
    return hllSketchImpl.getCompositeEstimate();
1✔
340
  }
341

342
  @Override
343
  public double getEstimate() {
344
    return hllSketchImpl.getEstimate();
1✔
345
  }
346

347
  double getHipEstimate() {
348
    return hllSketchImpl.getHipEstimate();
1✔
349
  }
350

351
  @Override
352
  public int getLgConfigK() {
353
    return hllSketchImpl.getLgConfigK();
1✔
354
  }
355

356
  @Override
357
  public int getCompactSerializationBytes() {
358
    return hllSketchImpl.getCompactSerializationBytes();
1✔
359
  }
360

361
  @Override
362
  public double getLowerBound(final int numStdDev) {
363
    return hllSketchImpl.getLowerBound(numStdDev);
1✔
364
  }
365

366
  /**
367
   * Returns the maximum size in bytes that this sketch can grow to given lgConfigK.
368
   * However, for the HLL_4 sketch type, this value can be exceeded in extremely rare cases.
369
   * If exceeded, it will be larger by only a few percent.
370
   *
371
   * @param lgConfigK The Log2 of K for the target HLL sketch. This value must be
372
   * between 4 and 21 inclusively.
373
   * @param tgtHllType the desired Hll type
374
   * @return the maximum size in bytes that this sketch can grow to.
375
   */
376
  public static final int getMaxUpdatableSerializationBytes(final int lgConfigK,
377
      final TgtHllType tgtHllType) {
378
    final int arrBytes;
379
    if (tgtHllType == TgtHllType.HLL_4) {
1✔
380
      final int auxBytes = 4 << LG_AUX_ARR_INTS[lgConfigK];
1✔
381
      arrBytes =  AbstractHllArray.hll4ArrBytes(lgConfigK) + auxBytes;
1✔
382
    }
1✔
383
    else if (tgtHllType == TgtHllType.HLL_6) {
1✔
384
      arrBytes = AbstractHllArray.hll6ArrBytes(lgConfigK);
1✔
385
    }
386
    else { //HLL_8
387
      arrBytes = AbstractHllArray.hll8ArrBytes(lgConfigK);
1✔
388
    }
389
    return HLL_BYTE_ARR_START + arrBytes;
1✔
390
  }
391

392
  Memory getMemory() {
393
    return hllSketchImpl.getMemory();
1✔
394
  }
395

396
  @Override
397
  public TgtHllType getTgtHllType() {
398
    return hllSketchImpl.getTgtHllType();
1✔
399
  }
400

401
  @Override
402
  public int getUpdatableSerializationBytes() {
403
    return hllSketchImpl.getUpdatableSerializationBytes();
1✔
404
  }
405

406
  WritableMemory getWritableMemory() {
407
    return hllSketchImpl.getWritableMemory();
1✔
408
  }
409

410
  @Override
411
  public double getUpperBound(final int numStdDev) {
412
    return hllSketchImpl.getUpperBound(numStdDev);
1✔
413
  }
414

415
  @Override
416
  public boolean isCompact() {
417
    return hllSketchImpl.isCompact();
1✔
418
  }
419

420
  @Override
421
  public boolean isEmpty() {
422
    return hllSketchImpl.isEmpty();
1✔
423
  }
424

425
  @Override
426
  public boolean isMemory() {
427
    return hllSketchImpl.isMemory();
1✔
428
  }
429

430
  @Override
431
  public boolean isOffHeap() {
432
    return hllSketchImpl.isOffHeap();
1✔
433
  }
434

435
  @Override
436
  boolean isOutOfOrder() {
437
    return hllSketchImpl.isOutOfOrder();
1✔
438
  }
439

440
  @Override
441
  public boolean isSameResource(final Memory mem) {
442
    return hllSketchImpl.isSameResource(mem);
1✔
443
  }
444

445
  void mergeTo(final HllSketch that) {
446
    hllSketchImpl.mergeTo(that);
1✔
447
  }
1✔
448

449
  HllSketch putOutOfOrderFlag(final boolean oooFlag) {
450
    hllSketchImpl.putOutOfOrder(oooFlag);
1✔
451
    return this;
1✔
452
  }
453

454
  @Override
455
  public void reset() {
456
    hllSketchImpl = hllSketchImpl.reset();
1✔
457
  }
1✔
458

459
  @Override
460
  public byte[] toCompactByteArray() {
461
    return hllSketchImpl.toCompactByteArray();
1✔
462
  }
463

464
  @Override
465
  public byte[] toUpdatableByteArray() {
466
    return hllSketchImpl.toUpdatableByteArray();
1✔
467
  }
468

469
  @Override
470
  public String toString(final boolean summary, final boolean detail, final boolean auxDetail,
471
      final boolean all) {
472
    final StringBuilder sb = new StringBuilder();
1✔
473
    if (summary) {
1✔
474
      sb.append("### HLL SKETCH SUMMARY: ").append(LS);
1✔
475
      sb.append("  Log Config K   : ").append(getLgConfigK()).append(LS);
1✔
476
      sb.append("  Hll Target     : ").append(getTgtHllType()).append(LS);
1✔
477
      sb.append("  Current Mode   : ").append(getCurMode()).append(LS);
1✔
478
      sb.append("  Memory         : ").append(isMemory()).append(LS);
1✔
479
      sb.append("  LB             : ").append(getLowerBound(1)).append(LS);
1✔
480
      sb.append("  Estimate       : ").append(getEstimate()).append(LS);
1✔
481
      sb.append("  UB             : ").append(getUpperBound(1)).append(LS);
1✔
482
      sb.append("  OutOfOrder Flag: ").append(isOutOfOrder()).append(LS);
1✔
483
      if (getCurMode() == CurMode.HLL) {
1✔
484
        final AbstractHllArray absHll = (AbstractHllArray) hllSketchImpl;
1✔
485
        sb.append("  CurMin         : ").append(absHll.getCurMin()).append(LS);
1✔
486
        sb.append("  NumAtCurMin    : ").append(absHll.getNumAtCurMin()).append(LS);
1✔
487
        sb.append("  HipAccum       : ").append(absHll.getHipAccum()).append(LS);
1✔
488
        sb.append("  KxQ0           : ").append(absHll.getKxQ0()).append(LS);
1✔
489
        sb.append("  KxQ1           : ").append(absHll.getKxQ1()).append(LS);
1✔
490
        sb.append("  Rebuild KxQ Flg: ").append(absHll.isRebuildCurMinNumKxQFlag()).append(LS);
1✔
491
      } else {
1✔
492
        sb.append("  Coupon Count   : ")
1✔
493
          .append(((AbstractCoupons)hllSketchImpl).getCouponCount()).append(LS);
1✔
494
      }
495
    }
496
    if (detail) {
1✔
497
      sb.append("### HLL SKETCH DATA DETAIL: ").append(LS);
1✔
498
      final PairIterator pitr = iterator();
1✔
499
      sb.append(pitr.getHeader()).append(LS);
1✔
500
      if (all) {
1✔
501
        while (pitr.nextAll()) {
1✔
502
          sb.append(pitr.getString()).append(LS);
1✔
503
        }
504
      } else {
505
        while (pitr.nextValid()) {
1✔
506
          sb.append(pitr.getString()).append(LS);
1✔
507
        }
508
      }
509
    }
510
    if (auxDetail) {
1✔
511
      if ((getCurMode() == CurMode.HLL) && (getTgtHllType() == TgtHllType.HLL_4)) {
1✔
512
        final AbstractHllArray absHll = (AbstractHllArray) hllSketchImpl;
1✔
513
        final PairIterator auxItr = absHll.getAuxIterator();
1✔
514
        if (auxItr != null) {
1✔
515
          sb.append("### HLL SKETCH AUX DETAIL: ").append(LS);
1✔
516
          sb.append(auxItr.getHeader()).append(LS);
1✔
517
          if (all) {
1✔
518
            while (auxItr.nextAll()) {
1✔
519
              sb.append(auxItr.getString()).append(LS);
1✔
520
            }
521
          } else {
522
            while (auxItr.nextValid()) {
1✔
523
              sb.append(auxItr.getString()).append(LS);
1✔
524
            }
525
          }
526
        }
527
      }
528
    }
529
    return sb.toString();
1✔
530
  }
531

532
  /**
533
   * Returns a human readable string of the preamble of a byte array image of an HllSketch.
534
   * @param byteArr the given byte array
535
   * @return a human readable string of the preamble of a byte array image of an HllSketch.
536
   */
537
  public static String toString(final byte[] byteArr) {
538
    return PreambleUtil.toString(byteArr);
×
539
  }
540

541
  /**
542
   * Returns a human readable string of the preamble of a Memory image of an HllSketch.
543
   * @param mem the given Memory object
544
   * @return a human readable string of the preamble of a Memory image of an HllSketch.
545
   */
546
  public static String toString(final Memory mem) {
547
    return PreambleUtil.toString(mem);
×
548
  }
549

550
  //restricted methods
551

552
  /**
553
   * Returns a PairIterator over the key, value pairs of the HLL array.
554
   * @return a PairIterator over the key, value pairs of the HLL array.
555
   */
556
  PairIterator iterator() {
557
    return hllSketchImpl.iterator();
1✔
558
  }
559

560
  @Override
561
  CurMode getCurMode() {
562
    return hllSketchImpl.getCurMode();
1✔
563
  }
564

565
  @Override
566
  void couponUpdate(final int coupon) {
567
    if ((coupon >>> KEY_BITS_26 ) == EMPTY) { return; }
1✔
568
    hllSketchImpl = hllSketchImpl.couponUpdate(coupon);
1✔
569
  }
1✔
570

571
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc