• 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

96.97
/src/main/java/org/apache/datasketches/kll/KllSketch.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.kll;
21

22
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR;
23
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_SINGLE_ITEM;
24
import static org.apache.datasketches.kll.KllPreambleUtil.N_LONG_ADR;
25
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_EMPTY_SINGLE;
26
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_FULL;
27
import static org.apache.datasketches.kll.KllPreambleUtil.SERIAL_VERSION_EMPTY_FULL;
28
import static org.apache.datasketches.kll.KllPreambleUtil.SERIAL_VERSION_SINGLE;
29
import static org.apache.datasketches.kll.KllPreambleUtil.SERIAL_VERSION_UPDATABLE;
30
import static org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_EMPTY;
31
import static org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_FULL;
32
import static org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_SINGLE;
33
import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;
34
import static org.apache.datasketches.kll.KllSketch.SketchType.DOUBLES_SKETCH;
35
import static org.apache.datasketches.kll.KllSketch.SketchType.FLOATS_SKETCH;
36
import static org.apache.datasketches.kll.KllSketch.SketchType.ITEMS_SKETCH;
37

38
import java.util.Arrays;
39
import java.util.Random;
40

41
import org.apache.datasketches.common.ArrayOfItemsSerDe;
42
import org.apache.datasketches.common.SketchesArgumentException;
43
import org.apache.datasketches.memory.Memory;
44
import org.apache.datasketches.memory.MemoryRequestServer;
45
import org.apache.datasketches.memory.WritableMemory;
46
import org.apache.datasketches.quantilescommon.QuantilesAPI;
47

48
/*
49
 * Sampled stream data (floats, doubles, or items) is stored as a heap array called itemsArr or as part of a
50
 * WritableMemory/Memory object.
51
 * This array is partitioned into sections called levels and the indices into the array of items
52
 * are tracked by a small integer array called levelsArr.
53
 * The data for level i lies in positions levelsArr[i] through levelsArr[i + 1] - 1 inclusive.
54
 * Hence, the levelsArr must contain (numLevels + 1) elements.
55
 * The valid portion of the itemsArr is completely packed and sorted, except for level 0,
56
 * which is filled from the top down. Any items below the index levelsArr[0] is free space and will be
57
 * overwritten by subsequent updates.
58
 *
59
 * Invariants:
60
 * 1) After a compaction, update, or a merge, every level is sorted except for level zero.
61
 * 2) After a compaction, (sum of level capacities) - (number of valid items) >= 1,
62
 *  so there is room for least 1 more quantile in level zero.
63
 * 3) There are no gaps except at the bottom, so if levelsArr[0] = 0,
64
 *  the sketch is exactly filled to capacity and must be compacted or the itemsArr and levelsArr
65
 *  must be expanded to include more levels.
66
 * 4) Sum of weights of all retained, valid items = N.
67
 * 5) Current total item capacity = itemsArr.length = levelsArr[numLevels].
68
 */
69

70
/**
71
 * This class is the root of the KLL sketch class hierarchy. It includes the public API that is independent
72
 * of either sketch type (e.g., float, double or generic item) and independent of whether the sketch is targeted
73
 * for use on the Java heap or off-heap.
74
 *
75
 * <p>KLL is an implementation of a very compact quantiles sketch with lazy compaction scheme
76
 * and nearly optimal accuracy per retained quantile.</p>
77
 *
78
 * <p>Reference <a href="https://arxiv.org/abs/1603.05346v2">Optimal Quantile Approximation in Streams</a>.</p>
79
 *
80
 * <p>The default <i>k</i> of 200 yields a "single-sided" epsilon of about 1.33% and a
81
 * "double-sided" (PMF) epsilon of about 1.65%, with a confidence of 99%.</p>
82
 *
83
 * @see <a href="https://datasketches.apache.org/docs/KLL/KLLSketch.html">KLL Sketch</a>
84
 * @see QuantilesAPI
85
 *
86
 * @author Lee Rhodes
87
 * @author Kevin Lang
88
 * @author Alexander Saydakov
89
 */
90
public abstract class KllSketch implements QuantilesAPI {
91

92
  /**
93
   * The default K
94
   */
95
  public static final int DEFAULT_K = 200;
96

97
  /**
98
   * The maximum K
99
   */
100
  public static final int MAX_K = (1 << 16) - 1; // serialized as an unsigned short
101

102
  /**
103
   * The default M. The parameter <i>m</i> is the minimum level size in number of quantiles.
104
   * Currently, the public default is 8, but this can be overridden using Package Private methods to
105
   * 2, 4, 6 or 8, and the sketch works just fine.  The number 8 was chosen as a compromise between speed and size.
106
   * Choosing an <i>m</i> smaller than 8 will make the sketch slower.
107
   */
108
  static final int DEFAULT_M = 8;
109
  static final int MAX_M = 8; //The maximum M
110
  static final int MIN_M = 2; //The minimum M
111
  static final Random random = new Random();
1✔
112

113
  final SketchType sketchType;
114
  final SketchStructure sketchStructure;
115
  boolean readOnly;
116
  int[] levelsArr; //Always updatable form
117

118
  /**
119
   * Constructor for on-heap and off-heap.
120
   * If both wmem and memReqSvr are null, this is a heap constructor.
121
   * If wmem != null and wmem is not readOnly, then memReqSvr must not be null.
122
   * If wmem was derived from an original Memory instance via a cast, it will be readOnly.
123
   * @param sketchType either DOUBLES_SKETCH, FLOATS_SKETCH or ITEMS_SKETCH
124
   * @param wmem  the current WritableMemory or null
125
   */
126
  KllSketch(
127
      final SketchType sketchType,
128
      final SketchStructure sketchStructure) {
1✔
129
   this.sketchType = sketchType;
1✔
130
   this.sketchStructure = sketchStructure;
1✔
131
  }
1✔
132

133
  /**
134
   * Gets the string value of the item at the given index.
135
   * @param index the index of the value
136
   * @return the string value of the item at the given index.
137
   */
138
  abstract String getItemAsString(int index);
139

140
  /**
141
   * Gets the approximate <em>k</em> to use given epsilon, the normalized rank error.
142
   * @param epsilon the normalized rank error between zero and one.
143
   * @param pmf if true, this function returns the <em>k</em> assuming the input epsilon
144
   * is the desired "double-sided" epsilon for the getPMF() function. Otherwise, this function
145
   * returns <em>k</em> assuming the input epsilon is the desired "single-sided"
146
   * epsilon for all the other queries.
147
   * @return <i>k</i> given epsilon.
148
   */
149
  public static int getKFromEpsilon(final double epsilon, final boolean pmf) {
150
    return KllHelper.getKFromEpsilon(epsilon, pmf);
1✔
151
  }
152

153
  /**
154
   * Returns upper bound on the serialized size of a KllSketch given the following parameters.
155
   * @param k parameter that controls size of the sketch and accuracy of estimates
156
   * @param n stream length
157
   * @param sketchType Only DOUBLES_SKETCH and FLOATS_SKETCH is supported for this operation.
158
   * @param updatableMemFormat true if updatable Memory format, otherwise the standard compact format.
159
   * @return upper bound on the serialized size of a KllSketch.
160
   */
161
  public static int getMaxSerializedSizeBytes(final int k, final long n,
162
      final SketchType sketchType, final boolean updatableMemFormat) {
163
    if (sketchType == ITEMS_SKETCH) { throw new SketchesArgumentException(UNSUPPORTED_MSG); }
1✔
164
    final KllHelper.GrowthStats gStats =
1✔
165
        KllHelper.getGrowthSchemeForGivenN(k, DEFAULT_M, n, sketchType, false);
1✔
166
    return updatableMemFormat ? gStats.updatableBytes : gStats.compactBytes;
1✔
167
  }
168

169
  /**
170
   * Gets the string value of the max item
171
   * @return the string value of the max item
172
   */
173
  abstract String getMaxItemAsString();
174

175
  /**
176
   * Gets the string value of the min item
177
   * @return the string value of the min item
178
   */
179
  abstract String getMinItemAsString();
180

181
  /**
182
   * Gets the normalized rank error given k and pmf.
183
   * Static method version of the <i>getNormalizedRankError(boolean)</i>.
184
   * The epsilon returned is a best fit to 99 percent confidence empirically measured max error
185
   * in thousands of trials.
186
   * @param k the configuration parameter
187
   * @param pmf if true, returns the "double-sided" normalized rank error for the getPMF() function.
188
   * Otherwise, it is the "single-sided" normalized rank error for all the other queries.
189
   * @return if pmf is true, the normalized rank error for the getPMF() function.
190
   * Otherwise, it is the "single-sided" normalized rank error for all the other queries.
191
   */
192
  public static double getNormalizedRankError(final int k, final boolean pmf) {
193
    return KllHelper.getNormalizedRankError(k, pmf);
1✔
194
  }
195

196
  @Override
197
  public final double getNormalizedRankError(final boolean pmf) {
198
    return getNormalizedRankError(getMinK(), pmf);
1✔
199
  }
200

201
  @Override
202
  public final int getNumRetained() {
203
    return levelsArr[getNumLevels()] - levelsArr[0];
1✔
204
  }
205

206
  /**
207
   * Returns the current number of bytes this Sketch would require if serialized in compact form.
208
   * @return the number of bytes this sketch would require if serialized.
209
   */
210
  public int getSerializedSizeBytes() {
211
    //current policy is that public method cannot return Updatable structure:
212
    return currentSerializedSizeBytes(false);
1✔
213
  }
214

215
  @Override
216
  public boolean hasMemory() {
217
    final WritableMemory wmem = getWritableMemory();
1✔
218
    return (wmem != null);
1✔
219
  }
220

221
  /**
222
   * Returns true if this sketch is in a Compact Memory Format.
223
   * @return true if this sketch is in a Compact Memory Format.
224
   */
225
  public boolean isCompactMemoryFormat() {
226
    return hasMemory() && sketchStructure != UPDATABLE;
1✔
227
  }
228

229
  @Override
230
  public boolean isDirect() {
231
    final WritableMemory wmem = getWritableMemory();
1✔
232
    return (wmem != null) ? wmem.isDirect() : false;
1✔
233
  }
234

235
  @Override
236
  public final boolean isEmpty() {
237
    return getN() == 0;
1✔
238
  }
239

240
  @Override
241
  public final boolean isEstimationMode() {
242
    return getNumLevels() > 1;
1✔
243
  }
244

245
  /**
246
   * Returns true if the backing WritableMemory is in updatable format.
247
   * @return true if the backing WritableMemory is in updatable format.
248
   */
249
  public final boolean isMemoryUpdatableFormat() {
250
    return hasMemory() && sketchStructure == UPDATABLE;
1✔
251
  }
252

253
  @Override
254
  public final boolean isReadOnly() {
255
    return readOnly;
1✔
256
  }
257

258
  /**
259
   * Returns true if the backing resource of <i>this</i> is identical with the backing resource
260
   * of <i>that</i>. The capacities must be the same.  If <i>this</i> is a region,
261
   * the region offset must also be the same.
262
   * @param that A different non-null object
263
   * @return true if the backing resource of <i>this</i> is the same as the backing resource
264
   * of <i>that</i>.
265
   */
266
  public final boolean isSameResource(final Memory that) {
267
    final WritableMemory wmem = getWritableMemory();
1✔
268
    return (wmem != null) && wmem.isSameResource(that);
1✔
269
  }
270

271
  /**
272
   * Merges another sketch into this one.
273
   * Attempting to merge a sketch of the wrong type will throw an exception.
274
   * @param other sketch to merge into this one
275
   */
276
  public abstract void merge(KllSketch other);
277

278
  @Override
279
  public final String toString() {
280
    return toString(false, false);
1✔
281
  }
282

283
  /**
284
   * Returns human readable summary information about this sketch.
285
   * Used for debugging.
286
   * @param withLevels if true includes sketch levels array summary information
287
   * @param withLevelsAndItems if true include detail of levels array and items array together
288
   * @return human readable summary information about this sketch.
289
   */
290
  public abstract String toString(final boolean withLevels, final boolean withLevelsAndItems);
291

292
  //restricted
293

294
  /**
295
   * Compute serialized size in bytes independent of the current sketch.
296
   * For KllItemsSketch the result is always in non-updatable, compact form.
297
   * @param updatable true if the desired result is for updatable structure.
298
   * @return serialized size in bytes given a SketchStructure.
299
   */
300
  final int currentSerializedSizeBytes(final boolean updatable) {
301
    final boolean myUpdatable = sketchType == ITEMS_SKETCH ? false : updatable;
1✔
302
    final long srcN = this.getN();
1✔
303
    final SketchStructure tgtStructure;
304
    if (myUpdatable) { tgtStructure = UPDATABLE; }
1✔
305
    else if (srcN == 0) { tgtStructure = COMPACT_EMPTY; }
1✔
306
    else if (srcN == 1) { tgtStructure = COMPACT_SINGLE; }
1✔
307
    else { tgtStructure = COMPACT_FULL; }
1✔
308
    final int totalBytes;
309
    if (tgtStructure == COMPACT_EMPTY) {
1✔
310
      totalBytes = N_LONG_ADR;
1✔
311
    }
312
    else if (tgtStructure == COMPACT_SINGLE) {
1✔
313
      totalBytes = DATA_START_ADR_SINGLE_ITEM
1✔
314
          + getSingleItemSizeBytes();
1✔
315
    }
316
    else if (tgtStructure == COMPACT_FULL) {
1✔
317
      totalBytes = DATA_START_ADR
1✔
318
          + getLevelsArrSizeBytes(tgtStructure)
1✔
319
          + getMinMaxSizeBytes()
1✔
320
          + getRetainedItemsSizeBytes();
1✔
321
    }
322
    else { //structure = UPDATABLE
323
      totalBytes = DATA_START_ADR
1✔
324
          + getLevelsArrSizeBytes(tgtStructure)
1✔
325
          + getMinMaxSizeBytes()
1✔
326
          + getTotalItemsNumBytes();
1✔
327
    }
328
    return totalBytes;
1✔
329
  }
330

331
  int[] getLevelsArray(final SketchStructure structure) {
332
    if (structure == UPDATABLE) { return levelsArr.clone(); }
1✔
333
    else if (structure == COMPACT_FULL) { return Arrays.copyOf(levelsArr, levelsArr.length - 1); }
1✔
334
    else { return new int[0]; }
×
335
  }
336

337
  final int getLevelsArrSizeBytes(final SketchStructure structure) {
338
    if (structure == UPDATABLE) { return levelsArr.length * Integer.BYTES; }
1✔
339
    else if (structure == COMPACT_FULL) { return (levelsArr.length - 1) * Integer.BYTES; }
1✔
340
    else { return 0; }
×
341
  }
342

343
  /**
344
   * Returns the configured parameter <i>m</i>, which is the minimum level size in number of items.
345
   * Currently, the public default is 8, but this can be overridden using Package Private methods to
346
   * 2, 4, 6 or 8, and the sketch works just fine.  The number 8 was chosen as a compromise between speed and size.
347
   * Choosing smaller <i>m</i> will make the sketch much slower.
348
   * @return the configured parameter m
349
   */
350
  abstract int getM();
351

352
  /**
353
   * Gets the MemoryRequestServer or null.
354
   * @return the MemoryRequestServer or null.
355
   */
356
  abstract MemoryRequestServer getMemoryRequestServer();
357

358
  /**
359
   * MinK is the K that results from a merge with a sketch configured with a K lower than
360
   * the K of this sketch. This is then used in computing the estimated upper and lower bounds of error.
361
   * @return The minimum K as a result of merging sketches with lower k.
362
   */
363
  abstract int getMinK();
364

365
  /**
366
   * Gets the combined minItem and maxItem in a serialized byte array.
367
   * @return the combined minItem and maxItem in a serialized byte array.
368
   */
369
  abstract byte[] getMinMaxByteArr();
370

371
  /**
372
   * Gets the size in bytes of the combined minItem and maxItem serialized byte array.
373
   * @return the size in bytes of the combined minItem and maxItem serialized byte array.
374
   */
375
  abstract int getMinMaxSizeBytes();
376

377
  /**
378
   * Gets the current number of levels
379
   * @return the current number of levels
380
   */
381
  final int getNumLevels() {
382
    if (sketchStructure == UPDATABLE || sketchStructure == COMPACT_FULL) { return levelsArr.length - 1; }
1✔
383
    return 1;
1✔
384
  }
385

386
  /**
387
   * Gets the serialized byte array of the valid retained items as a byte array.
388
   * It does not include the preamble, the levels array, minimum or maximum items, or free space.
389
   * @return the serialized bytes of the retained data.
390
   */
391
  abstract byte[] getRetainedItemsByteArr();
392

393
  /**
394
   * Gets the size in bytes of the valid retained items.
395
   * It does not include the preamble, the levels array, minimum or maximum items, or free space.
396
   * @return the size of the retained data in bytes.
397
   */
398
  abstract int getRetainedItemsSizeBytes();
399

400
  /**
401
   * Gets the serializer / deserializer or null.
402
   * @return the serializer / deserializer or null.
403
   */
404
  abstract ArrayOfItemsSerDe<?> getSerDe();
405

406
  /**
407
   * Gets the serialized byte array of the Single Item that corresponds to the Single Item Flag being true.
408
   * @return the serialized byte array of the Single Item.
409
   */
410
  abstract byte[] getSingleItemByteArr();
411

412
  /**
413
   * Gets the size in bytes of the serialized Single Item that corresponds to the Single Item Flag being true.
414
   * @return the size in bytes of the serialized Single Item.
415
   */
416
  abstract int getSingleItemSizeBytes();
417

418
  /**
419
   * Gets the serialized byte array of the entire internal items hypothetical structure.
420
   * It does not include the preamble, the levels array, or minimum or maximum items.
421
   * It may include empty or free space.
422
   * @return the serialized bytes of the retained data.
423
   */
424
  abstract byte[] getTotalItemsByteArr();
425

426
  /**
427
   * Gets the size in bytes of the entire internal items hypothetical structure.
428
   * It does not include the preamble, the levels array, or minimum or maximum items.
429
   * It may include empty or free space.
430
   * @return the size of the retained data in bytes.
431
   */
432
  abstract int getTotalItemsNumBytes();
433

434
  /**
435
   * This returns the WritableMemory for Direct type sketches,
436
   * otherwise returns null.
437
   * @return the WritableMemory for Direct type sketches, otherwise null.
438
   */
439
  abstract WritableMemory getWritableMemory();
440

441
  abstract void incN(int increment);
442

443
  abstract void incNumLevels();
444

445
  final boolean isCompactSingleItem() {
446
    return hasMemory() && sketchStructure == COMPACT_SINGLE && (getN() == 1);
1✔
447
  }
448

449
  boolean isDoublesSketch() { return sketchType == DOUBLES_SKETCH; }
1✔
450

451
  boolean isFloatsSketch() { return sketchType == FLOATS_SKETCH; }
1✔
452

453
  boolean isItemsSketch() { return sketchType == ITEMS_SKETCH; }
×
454

455
  abstract boolean isLevelZeroSorted();
456

457
  /**
458
   * @return true if N == 1.
459
   */
460
  boolean isSingleItem() { return getN() == 1; }
1✔
461

462
  final void setLevelsArray(final int[] levelsArr) {
463
    if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
1✔
464
    this.levelsArr = levelsArr;
1✔
465
    final WritableMemory wmem = getWritableMemory();
1✔
466
    if (wmem != null) {
1✔
467
      wmem.putIntArray(DATA_START_ADR, this.levelsArr, 0, levelsArr.length);
1✔
468
    }
469
  }
1✔
470

471
  final void setLevelsArrayAt(final int index, final int idxVal) {
472
    if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
1✔
473
    this.levelsArr[index] = idxVal;
1✔
474
    final WritableMemory wmem = getWritableMemory();
1✔
475
    if (wmem != null) {
1✔
476
      final int offset = DATA_START_ADR + index * Integer.BYTES;
1✔
477
      wmem.putInt(offset, idxVal);
1✔
478
    }
479
  }
1✔
480

481
  abstract void setLevelZeroSorted(boolean sorted);
482

483
  abstract void setMinK(int minK);
484

485
  abstract void setN(long n);
486

487
  abstract void setNumLevels(int numLevels);
488

489
  abstract void setWritableMemory(final WritableMemory wmem);
490

491
  /**
492
   * Used to define the variable type of the current instance of this class.
493
   */
494
  public enum SketchType {
1✔
495
    /**
496
     * KllDoublesSketch
497
     */
498
    DOUBLES_SKETCH(Double.BYTES, "KllDoublesSketch"),
1✔
499
    /**
500
     * KllFloatsSketch
501
     */
502
    FLOATS_SKETCH(Float.BYTES, "KllFloatsSketch"),
1✔
503
    /**
504
     * KllItemsSketch
505
     */
506
    ITEMS_SKETCH(0, "KllItemsSketch");
1✔
507

508
    private int typeBytes;
509
    private String name;
510

511
    private SketchType(final int typeBytes, final String name) {
1✔
512
      this.typeBytes = typeBytes;
1✔
513
      this.name = name;
1✔
514
    }
1✔
515

516
    /**
517
     * Gets the item size in bytes. If the item is generic, this returns zero.
518
     * @return the item size in bytes
519
     */
520
    public int getBytes() { return typeBytes; }
1✔
521

522
    /**
523
     * Get the name of the associated sketch
524
     * @return the name of the associated sketch
525
     */
526
    public String getName() { return name; }
1✔
527
  }
528

529
  /**
530
   * Used primarily to define the structure of the serialized sketch. Also used by the Heap Sketch.
531
   */
532
  public enum SketchStructure {
1✔
533
    /** Compact Empty Structure */
534
    COMPACT_EMPTY(PREAMBLE_INTS_EMPTY_SINGLE, SERIAL_VERSION_EMPTY_FULL),
1✔
535
    /** Compact Single Item Structure */
536
    COMPACT_SINGLE(PREAMBLE_INTS_EMPTY_SINGLE, SERIAL_VERSION_SINGLE),
1✔
537
    /** Compact Full Preamble Structure */
538
    COMPACT_FULL(PREAMBLE_INTS_FULL, SERIAL_VERSION_EMPTY_FULL),
1✔
539
    /** Updatable Preamble Structure */
540
    UPDATABLE(PREAMBLE_INTS_FULL, SERIAL_VERSION_UPDATABLE); //also used by the heap sketch.
1✔
541

542
    private int preInts;
543
    private int serVer;
544

545
    private SketchStructure(final int preInts, final int serVer) {
1✔
546
      this.preInts = preInts;
1✔
547
      this.serVer = serVer;
1✔
548
    }
1✔
549

550
    /**
551
     * gets the Preamble Integers for this Structure.
552
     * @return the Preamble Integers for this Structure
553
     */
554
    public int getPreInts() { return preInts; }
1✔
555

556
    /**
557
     * gets the Serialization Version for this Structure.
558
     * @return the Serialization Version for this Structure.
559
     */
560
    public int getSerVer() { return serVer; }
1✔
561

562
    /**
563
     * gets the SketchStructure given preInts and serVer.
564
     * @param preInts the given preamble size in integers
565
     * @param serVer the given Serialization Version
566
     * @return the SketchStructure given preInts and serVer.
567
     */
568
    public static SketchStructure getSketchStructure(final int preInts, final int serVer) {
569
      final SketchStructure[] ssArr = SketchStructure.values();
1✔
570
      for (int i = 0; i < ssArr.length; i++) {
1✔
571
        if (ssArr[i].preInts == preInts && ssArr[i].serVer == serVer) {
1✔
572
          return ssArr[i];
1✔
573
        }
574
      }
575
      throw new SketchesArgumentException("Error combination of PreInts and SerVer: "
1✔
576
          + "PreInts: " + preInts + ", SerVer: " + serVer);
577
    }
578
  }
579

580
}
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