• 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

99.52
/src/main/java/org/apache/datasketches/theta/UnionImpl.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.theta;
21

22
import static java.lang.Math.min;
23
import static org.apache.datasketches.theta.PreambleUtil.COMPACT_FLAG_MASK;
24
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
25
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
26
import static org.apache.datasketches.theta.PreambleUtil.UNION_THETA_LONG;
27
import static org.apache.datasketches.theta.PreambleUtil.clearEmpty;
28
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
29
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
30
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
31
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
32
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
33
import static org.apache.datasketches.theta.PreambleUtil.extractSeedHash;
34
import static org.apache.datasketches.theta.PreambleUtil.extractSerVer;
35
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
36
import static org.apache.datasketches.theta.PreambleUtil.extractUnionThetaLong;
37
import static org.apache.datasketches.theta.PreambleUtil.insertUnionThetaLong;
38
import static org.apache.datasketches.theta.SingleItemSketch.otherCheckForSingleItem;
39
import static org.apache.datasketches.thetacommon.QuickSelect.selectExcludingZeros;
40

41
import java.nio.ByteBuffer;
42

43
import org.apache.datasketches.common.Family;
44
import org.apache.datasketches.common.ResizeFactor;
45
import org.apache.datasketches.common.SketchesArgumentException;
46
import org.apache.datasketches.memory.Memory;
47
import org.apache.datasketches.memory.MemoryRequestServer;
48
import org.apache.datasketches.memory.WritableMemory;
49
import org.apache.datasketches.thetacommon.HashOperations;
50
import org.apache.datasketches.thetacommon.ThetaUtil;
51

52
/**
53
 * Shared code for the HeapUnion and DirectUnion implementations.
54
 *
55
 * @author Lee Rhodes
56
 * @author Kevin Lang
57
 */
58
final class UnionImpl extends Union {
59

60
  /**
61
   * Although the gadget object is initially an UpdateSketch, in the context of a Union it is used
62
   * as a specialized buffer that happens to leverage much of the machinery of an UpdateSketch.
63
   * However, in this context some of the key invariants of the sketch algorithm are intentionally
64
   * violated as an optimization. As a result this object can not be considered as an UpdateSketch
65
   * and should never be exported as an UpdateSketch. It's internal state is not necessarily
66
   * finalized and may contain garbage. Also its internal concept of "nominal entries" or "k" can
67
   * be meaningless. It is private for very good reasons.
68
   */
69
  private final UpdateSketch gadget_;
70
  private final short expectedSeedHash_; //eliminates having to compute the seedHash on every union.
71
  private long unionThetaLong_; //when on-heap, this is the only copy
72
  private boolean unionEmpty_;  //when on-heap, this is the only copy
73

74
  private UnionImpl(final UpdateSketch gadget, final long seed) {
1✔
75
    gadget_ = gadget;
1✔
76
    expectedSeedHash_ = ThetaUtil.computeSeedHash(seed);
1✔
77
  }
1✔
78

79
  /**
80
   * Construct a new Union SetOperation on the java heap.
81
   * Called by SetOperationBuilder.
82
   *
83
   * @param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLogs">See lgNomLongs</a>
84
   * @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
85
   * @param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
86
   * @param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
87
   * @return instance of this sketch
88
   */
89
  static UnionImpl initNewHeapInstance(
90
      final int lgNomLongs,
91
      final long seed,
92
      final float p,
93
      final ResizeFactor rf) {
94
    final UpdateSketch gadget = //create with UNION family
1✔
95
        new HeapQuickSelectSketch(lgNomLongs, seed, p, rf, true);
96
    final UnionImpl unionImpl = new UnionImpl(gadget, seed);
1✔
97
    unionImpl.unionThetaLong_ = gadget.getThetaLong();
1✔
98
    unionImpl.unionEmpty_ = gadget.isEmpty();
1✔
99
    return unionImpl;
1✔
100
  }
101

102
  /**
103
   * Construct a new Direct Union in the off-heap destination Memory.
104
   * Called by SetOperationBuilder.
105
   *
106
   * @param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLogs">See lgNomLongs</a>.
107
   * @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
108
   * @param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
109
   * @param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
110
   * @param memReqSvr a given instance of a MemoryRequestServer
111
   * @param dstMem the given Memory object destination. It will be cleared prior to use.
112
   * @return this class
113
   */
114
  static UnionImpl initNewDirectInstance(
115
      final int lgNomLongs,
116
      final long seed,
117
      final float p,
118
      final ResizeFactor rf,
119
      final MemoryRequestServer memReqSvr,
120
      final WritableMemory dstMem) {
121
    final UpdateSketch gadget = //create with UNION family
1✔
122
        new DirectQuickSelectSketch(lgNomLongs, seed, p, rf, memReqSvr, dstMem, true);
123
    final UnionImpl unionImpl = new UnionImpl(gadget, seed);
1✔
124
    unionImpl.unionThetaLong_ = gadget.getThetaLong();
1✔
125
    unionImpl.unionEmpty_ = gadget.isEmpty();
1✔
126
    return unionImpl;
1✔
127
  }
128

129
  /**
130
   * Heapify a Union from a Memory Union object containing data.
131
   * Called by SetOperation.
132
   * @param srcMem The source Memory Union object.
133
   * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
134
   * @param expectedSeed the seed used to validate the given Memory image.
135
   * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
136
   * @return this class
137
   */
138
  static UnionImpl heapifyInstance(final Memory srcMem, final long expectedSeed) {
139
    Family.UNION.checkFamilyID(extractFamilyID(srcMem));
1✔
140
    final UpdateSketch gadget = HeapQuickSelectSketch.heapifyInstance(srcMem, expectedSeed);
1✔
141
    final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
1✔
142
    unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
1✔
143
    unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
1✔
144
    return unionImpl;
1✔
145
  }
146

147
  /**
148
   * Fast-wrap a Union object around a Union Memory object containing data.
149
   * This does NO validity checking of the given Memory.
150
   * @param srcMem The source Memory object.
151
   * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
152
   * @param expectedSeed the seed used to validate the given Memory image.
153
   * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
154
   * @return this class
155
   */
156
  static UnionImpl fastWrap(final Memory srcMem, final long expectedSeed) {
157
    Family.UNION.checkFamilyID(extractFamilyID(srcMem));
1✔
158
    final UpdateSketch gadget = DirectQuickSelectSketchR.fastReadOnlyWrap(srcMem, expectedSeed);
1✔
159
    final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
1✔
160
    unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
1✔
161
    unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
1✔
162
    return unionImpl;
1✔
163
  }
164

165
  /**
166
   * Fast-wrap a Union object around a Union WritableMemory object containing data.
167
   * This does NO validity checking of the given Memory.
168
   * @param srcMem The source Memory object.
169
   * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
170
   * @param expectedSeed the seed used to validate the given Memory image.
171
   * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
172
   * @return this class
173
   */
174
  static UnionImpl fastWrap(final WritableMemory srcMem, final long expectedSeed) {
175
    Family.UNION.checkFamilyID(extractFamilyID(srcMem));
1✔
176
    final UpdateSketch gadget = DirectQuickSelectSketch.fastWritableWrap(srcMem, expectedSeed);
1✔
177
    final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
1✔
178
    unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
1✔
179
    unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
1✔
180
    return unionImpl;
1✔
181
  }
182

183
  /**
184
   * Wrap a Union object around a Union Memory object containing data.
185
   * Called by SetOperation.
186
   * @param srcMem The source Memory object.
187
   * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
188
   * @param expectedSeed the seed used to validate the given Memory image.
189
   * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
190
   * @return this class
191
   */
192
  static UnionImpl wrapInstance(final Memory srcMem, final long expectedSeed) {
193
    Family.UNION.checkFamilyID(extractFamilyID(srcMem));
1✔
194
    final UpdateSketch gadget = DirectQuickSelectSketchR.readOnlyWrap(srcMem, expectedSeed);
1✔
195
    final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
1✔
196
    unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
1✔
197
    unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
1✔
198
    return unionImpl;
1✔
199
  }
200

201
  /**
202
   * Wrap a Union object around a Union WritableMemory object containing data.
203
   * Called by SetOperation.
204
   * @param srcMem The source Memory object.
205
   * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
206
   * @param expectedSeed the seed used to validate the given Memory image.
207
   * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
208
   * @return this class
209
   */
210
  static UnionImpl wrapInstance(final WritableMemory srcMem, final long expectedSeed) {
211
    Family.UNION.checkFamilyID(extractFamilyID(srcMem));
1✔
212
    final UpdateSketch gadget = DirectQuickSelectSketch.writableWrap(srcMem, expectedSeed);
1✔
213
    final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
1✔
214
    unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
1✔
215
    unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
1✔
216
    return unionImpl;
1✔
217
  }
218

219
  @Override
220
  public int getCurrentBytes() {
221
    return gadget_.getCurrentBytes();
1✔
222
  }
223

224
  @Override
225
  public int getMaxUnionBytes() {
226
    final int lgK = gadget_.getLgNomLongs();
1✔
227
    return (16 << lgK) + (Family.UNION.getMaxPreLongs() << 3);
1✔
228
  }
229

230
  @Override
231
  public CompactSketch getResult() {
232
    return getResult(true, null);
1✔
233
  }
234

235
  @Override
236
  public CompactSketch getResult(final boolean dstOrdered, final WritableMemory dstMem) {
237
    final int gadgetCurCount = gadget_.getRetainedEntries(true);
1✔
238
    final int k = 1 << gadget_.getLgNomLongs();
1✔
239
    final long[] gadgetCacheCopy =
1✔
240
        gadget_.hasMemory() ? gadget_.getCache() : gadget_.getCache().clone();
1✔
241

242
    //Pull back to k
243
    final long curGadgetThetaLong = gadget_.getThetaLong();
1✔
244
    final long adjGadgetThetaLong = gadgetCurCount > k
1✔
245
        ? selectExcludingZeros(gadgetCacheCopy, gadgetCurCount, k + 1) : curGadgetThetaLong;
1✔
246

247
    //Finalize Theta and curCount
248
    final long unionThetaLong = gadget_.hasMemory()
1✔
249
        ? gadget_.getMemory().getLong(UNION_THETA_LONG) : unionThetaLong_;
1✔
250

251
    final long minThetaLong = min(min(curGadgetThetaLong, adjGadgetThetaLong), unionThetaLong);
1✔
252
    final int curCountOut = minThetaLong < curGadgetThetaLong
1✔
253
        ? HashOperations.count(gadgetCacheCopy, minThetaLong)
1✔
254
        : gadgetCurCount;
255

256
    //Compact the cache
257
    final long[] compactCacheOut =
1✔
258
        CompactOperations.compactCache(gadgetCacheCopy, curCountOut, minThetaLong, dstOrdered);
1✔
259
    final boolean empty = gadget_.isEmpty() && unionEmpty_;
1✔
260
    final short seedHash = gadget_.getSeedHash();
1✔
261
    return CompactOperations.componentsToCompact(
1✔
262
        minThetaLong, curCountOut, seedHash, empty, true, dstOrdered, dstOrdered, dstMem, compactCacheOut);
263
  }
264

265
  @Override
266
  public boolean isSameResource(final Memory that) {
267
    return gadget_ instanceof DirectQuickSelectSketchR
1✔
268
        ? gadget_.getMemory().isSameResource(that) : false;
1✔
269
  }
270

271
  @Override
272
  public void reset() {
273
    gadget_.reset();
1✔
274
    unionThetaLong_ = gadget_.getThetaLong();
1✔
275
    unionEmpty_ = gadget_.isEmpty();
1✔
276
  }
1✔
277

278
  @Override
279
  public byte[] toByteArray() {
280
    final byte[] gadgetByteArr = gadget_.toByteArray();
1✔
281
    final WritableMemory mem = WritableMemory.writableWrap(gadgetByteArr);
1✔
282
    insertUnionThetaLong(mem, unionThetaLong_);
1✔
283
    if (gadget_.isEmpty() != unionEmpty_) {
1✔
284
      clearEmpty(mem);
1✔
285
      unionEmpty_ = false;
1✔
286
    }
287
    return gadgetByteArr;
1✔
288
  }
289

290
  @Override //Stateless Union
291
  public CompactSketch union(final Sketch sketchA, final Sketch sketchB, final boolean dstOrdered,
292
      final WritableMemory dstMem) {
293
    reset();
1✔
294
    union(sketchA);
1✔
295
    union(sketchB);
1✔
296
    final CompactSketch csk = getResult(dstOrdered, dstMem);
1✔
297
    reset();
1✔
298
    return csk;
1✔
299
  }
300

301
  @Override
302
  public void union(final Sketch sketchIn) {
303
    //UNION Empty Rule: AND the empty states.
304

305
    if (sketchIn == null || sketchIn.isEmpty()) {
1✔
306
      //null and empty is interpreted as (Theta = 1.0, count = 0, empty = T).  Nothing changes
307
      return;
1✔
308
    }
309
    //sketchIn is valid and not empty
310
    ThetaUtil.checkSeedHashes(expectedSeedHash_, sketchIn.getSeedHash());
1✔
311
    if (sketchIn instanceof SingleItemSketch) {
1✔
312
      gadget_.hashUpdate(sketchIn.getCache()[0]);
1✔
313
      return;
1✔
314
    }
315
    Sketch.checkSketchAndMemoryFlags(sketchIn);
1✔
316

317
    unionThetaLong_ = min(min(unionThetaLong_, sketchIn.getThetaLong()), gadget_.getThetaLong()); //Theta rule
1✔
318
    unionEmpty_ = false;
1✔
319
    final int curCountIn = sketchIn.getRetainedEntries(true);
1✔
320
    if (curCountIn > 0) {
1✔
321
      if (sketchIn.isOrdered() && (sketchIn instanceof CompactSketch)) { //Use early stop
1✔
322
        //Ordered, thus compact
323
        if (sketchIn.hasMemory()) {
1✔
324
          final Memory skMem = ((CompactSketch) sketchIn).getMemory();
1✔
325
          final int preambleLongs = skMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
1✔
326
          for (int i = 0; i < curCountIn; i++ ) {
1✔
327
            final int offsetBytes = preambleLongs + i << 3;
1✔
328
            final long hashIn = skMem.getLong(offsetBytes);
1✔
329
            if (hashIn >= unionThetaLong_) { break; } // "early stop"
1✔
330
            gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
1✔
331
          }
332
        }
1✔
333
        else { //sketchIn is on the Java Heap or has array
334
          final long[] cacheIn = sketchIn.getCache(); //not a copy!
1✔
335
          for (int i = 0; i < curCountIn; i++ ) {
1✔
336
            final long hashIn = cacheIn[i];
1✔
337
            if (hashIn >= unionThetaLong_) { break; } // "early stop"
1✔
338
            gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
1✔
339
          }
340
        }
1✔
341
      } //End ordered, compact
342
      else { //either not-ordered compact or Hash Table form. A HT may have dirty values.
343
        final long[] cacheIn = sketchIn.getCache(); //if off-heap this will be a copy
1✔
344
        final int arrLongs = cacheIn.length;
1✔
345
        for (int i = 0, c = 0; i < arrLongs && c < curCountIn; i++ ) {
1✔
346
          final long hashIn = cacheIn[i];
1✔
347
          if (hashIn <= 0L || hashIn >= unionThetaLong_) { continue; } //rejects dirty values
1✔
348
          gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
1✔
349
          c++; //ensures against invalid state inside the incoming sketch
1✔
350
        }
351
      }
352
    }
353
    unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong()); //Theta rule with gadget
1✔
354
    if (gadget_.hasMemory()) {
1✔
355
      final WritableMemory wmem = (WritableMemory)gadget_.getMemory();
1✔
356
      PreambleUtil.insertUnionThetaLong(wmem, unionThetaLong_);
1✔
357
      PreambleUtil.clearEmpty(wmem);
1✔
358
    }
359
  }
1✔
360

361
  @Override
362
  public void union(final Memory skMem) {
363
    if (skMem == null) { return; }
1✔
364
    final int cap = (int) skMem.getCapacity();
1✔
365
    if (cap < 16) { return; } //empty or garbage
1✔
366
    final int serVer = extractSerVer(skMem);
1✔
367
    final int fam = extractFamilyID(skMem);
1✔
368

369
    if (serVer == 4) { // compressed ordered compact
1✔
370
      // performance can be improved by decompression while performing the union
371
      // potentially only partial decompression might be needed
372
      ThetaUtil.checkSeedHashes(expectedSeedHash_, (short) extractSeedHash(skMem));
1✔
373
      final CompactSketch csk = CompactSketch.wrap(skMem);
1✔
374
      union(csk);
1✔
375
      return;
1✔
376
    }
377
    if (serVer == 3) { //The OpenSource sketches (Aug 4, 2015) starts with serVer = 3
1✔
378
      if (fam < 1 || fam > 3) {
1✔
379
        throw new SketchesArgumentException(
1✔
380
            "Family must be Alpha, QuickSelect, or Compact: " + Family.idToFamily(fam));
×
381
      }
382
      processVer3(skMem);
1✔
383
      return;
1✔
384
    }
385
    if (serVer == 2) { //older Sketch, which is compact and ordered
1✔
386
      ThetaUtil.checkSeedHashes(expectedSeedHash_, (short)extractSeedHash(skMem));
1✔
387
      final CompactSketch csk = ForwardCompatibility.heapify2to3(skMem, expectedSeedHash_);
1✔
388
      union(csk);
1✔
389
      return;
1✔
390
    }
391
    if (serVer == 1) { //much older Sketch, which is compact and ordered, no seedHash
1✔
392
      final CompactSketch csk = ForwardCompatibility.heapify1to3(skMem, expectedSeedHash_);
1✔
393
      union(csk);
1✔
394
      return;
1✔
395
    }
396

397
    throw new SketchesArgumentException("SerVer is unknown: " + serVer);
1✔
398
  }
399

400
  //Has seedHash, p, could have 0 entries & theta < 1.0,
401
  //could be unordered, ordered, compact, or not compact,
402
  //could be Alpha, QuickSelect, or Compact.
403
  private void processVer3(final Memory skMem) {
404
    final int preLongs = extractPreLongs(skMem);
1✔
405

406
    if (preLongs == 1) {
1✔
407
      if (otherCheckForSingleItem(skMem)) {
1✔
408
        final long hash = skMem.getLong(8);
1✔
409
        gadget_.hashUpdate(hash);
1✔
410
        return;
1✔
411
      }
412
      return; //empty
1✔
413
    }
414
    ThetaUtil.checkSeedHashes(expectedSeedHash_, (short)extractSeedHash(skMem));
1✔
415
    final int curCountIn;
416
    final long thetaLongIn;
417

418
    if (preLongs == 2) { //exact mode
1✔
419
      curCountIn = extractCurCount(skMem);
1✔
420
      if (curCountIn == 0) { return; } //should be > 0, but if it is 0 return empty anyway.
1✔
421
      thetaLongIn = Long.MAX_VALUE;
1✔
422
    }
423

424
    else { //prelongs == 3
425
      //curCount may be 0 (e.g., from intersection); but sketch cannot be empty.
426
      curCountIn = extractCurCount(skMem);
1✔
427
      thetaLongIn = extractThetaLong(skMem);
1✔
428
    }
429

430
    unionThetaLong_ = min(min(unionThetaLong_, thetaLongIn), gadget_.getThetaLong()); //theta rule
1✔
431
    unionEmpty_ = false;
1✔
432
    final int flags = extractFlags(skMem);
1✔
433
    final boolean ordered = (flags & ORDERED_FLAG_MASK) != 0;
1✔
434
    if (ordered) { //must be compact
1✔
435

436
      for (int i = 0; i < curCountIn; i++ ) {
1✔
437
        final int offsetBytes = preLongs + i << 3;
1✔
438
        final long hashIn = skMem.getLong(offsetBytes);
1✔
439
        if (hashIn >= unionThetaLong_) { break; } // "early stop"
1✔
440
        gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
1✔
441
      }
442
    }
443

444
    else { //not-ordered, could be compact or hash-table form
445
      final boolean compact = (flags & COMPACT_FLAG_MASK) != 0;
1✔
446
      final int size = compact ? curCountIn : 1 << extractLgArrLongs(skMem);
1✔
447

448
      for (int i = 0; i < size; i++ ) {
1✔
449
        final int offsetBytes = preLongs + i << 3;
1✔
450
        final long hashIn = skMem.getLong(offsetBytes);
1✔
451
        if (hashIn <= 0L || hashIn >= unionThetaLong_) { continue; }
1✔
452
        gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
1✔
453
      }
454
    }
455

456
    unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong()); //sync thetaLongs
1✔
457

458
    if (gadget_.hasMemory()) {
1✔
459
      final WritableMemory wmem = (WritableMemory)gadget_.getMemory();
1✔
460
      PreambleUtil.insertUnionThetaLong(wmem, unionThetaLong_);
1✔
461
      PreambleUtil.clearEmpty(wmem);
1✔
462
    }
463
  }
1✔
464

465
  @Override
466
  public void update(final long datum) {
467
    gadget_.update(datum);
1✔
468
  }
1✔
469

470
  @Override
471
  public void update(final double datum) {
472
    gadget_.update(datum);
1✔
473
  }
1✔
474

475
  @Override
476
  public void update(final String datum) {
477
    gadget_.update(datum);
1✔
478
  }
1✔
479

480
  @Override
481
  public void update(final byte[] data) {
482
    gadget_.update(data);
1✔
483
  }
1✔
484

485
  @Override
486
  public void update(final ByteBuffer data) {
487
    gadget_.update(data);
1✔
488
  }
1✔
489

490
  @Override
491
  public void update(final char[] data) {
492
    gadget_.update(data);
1✔
493
  }
1✔
494

495
  @Override
496
  public void update(final int[] data) {
497
    gadget_.update(data);
1✔
498
  }
1✔
499

500
  @Override
501
  public void update(final long[] data) {
502
    gadget_.update(data);
1✔
503
  }
1✔
504

505
  //Restricted
506

507
  @Override
508
  long[] getCache() {
509
    return gadget_.getCache();
1✔
510
  }
511

512
  @Override
513
  int getRetainedEntries() {
514
    return gadget_.getRetainedEntries(true);
1✔
515
  }
516

517
  @Override
518
  short getSeedHash() {
519
    return gadget_.getSeedHash();
1✔
520
  }
521

522
  @Override
523
  long getThetaLong() {
524
    return min(unionThetaLong_, gadget_.getThetaLong());
1✔
525
  }
526

527
  @Override
528
  boolean isEmpty() {
529
    return gadget_.isEmpty() && unionEmpty_;
1✔
530
  }
531

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