-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathIntersectionImpl.java
More file actions
563 lines (519 loc) · 21.3 KB
/
IntersectionImpl.java
File metadata and controls
563 lines (519 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.lang.Math.min;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.FAMILY_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.FLAGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.LG_ARR_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.LG_NOM_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.P_FLOAT;
import static org.apache.datasketches.theta.PreambleUtil.RETAINED_ENTRIES_INT;
import static org.apache.datasketches.theta.PreambleUtil.SEED_HASH_SHORT;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.THETA_LONG;
import static org.apache.datasketches.theta.PreambleUtil.clearEmpty;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.insertCurCount;
import static org.apache.datasketches.theta.PreambleUtil.insertFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.insertLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertP;
import static org.apache.datasketches.theta.PreambleUtil.insertPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertSerVer;
import static org.apache.datasketches.theta.PreambleUtil.insertThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.setEmpty;
import static org.apache.datasketches.thetacommon.HashOperations.continueCondition;
import static org.apache.datasketches.thetacommon.HashOperations.hashInsertOnly;
import static org.apache.datasketches.thetacommon.HashOperations.hashInsertOnlyMemory;
import static org.apache.datasketches.thetacommon.HashOperations.hashSearch;
import static org.apache.datasketches.thetacommon.HashOperations.minLgHashTableSize;
import java.util.Arrays;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesReadOnlyException;
import org.apache.datasketches.common.SketchesStateException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* Intersection operation for Theta Sketches.
*
* <p>This implementation uses data either on-heap or off-heap in a given Memory
* that is owned and managed by the caller.
* The off-heap Memory, which if managed properly, will greatly reduce the need for
* the JVM to perform garbage collection.</p>
*
* @author Lee Rhodes
* @author Kevin Lang
*/
class IntersectionImpl extends Intersection {
protected final short seedHash_;
protected final boolean readOnly_; //True if this sketch is to be treated as read only
protected final WritableMemory wmem_;
protected final int maxLgArrLongs_; //only used with WritableMemory, not serialized
//Note: Intersection does not use lgNomLongs or k, per se.
protected int lgArrLongs_; //current size of hash table
protected int curCount_; //curCount of HT, if < 0 means Universal Set (US) is true
protected long thetaLong_;
protected boolean empty_; //A virgin intersection represents the Universal Set, so empty is FALSE!
protected long[] hashTable_; //retained entries of the intersection, on-heap only.
/**
* Constructor: Sets the class finals and computes, sets and checks the seedHash.
* @param wmem Can be either a Source(e.g. wrap) or Destination (new Direct) WritableMemory.
* @param seed Used to validate incoming sketch arguments.
* @param dstMemFlag The given memory is a Destination (new Direct) WritableMemory.
* @param readOnly True if memory is to be treated as read only.
*/
protected IntersectionImpl(final WritableMemory wmem, final long seed, final boolean dstMemFlag,
final boolean readOnly) {
readOnly_ = readOnly;
if (wmem != null) {
wmem_ = wmem;
if (dstMemFlag) { //DstMem: compute & store seedHash, no seedhash checking
checkMinSizeMemory(wmem);
maxLgArrLongs_ = !readOnly ? getMaxLgArrLongs(wmem) : 0; //Only Off Heap
seedHash_ = ThetaUtil.computeSeedHash(seed);
wmem_.putShort(SEED_HASH_SHORT, seedHash_);
} else { //SrcMem:gets and stores the seedHash, checks mem_seedHash against the seed
seedHash_ = wmem_.getShort(SEED_HASH_SHORT);
ThetaUtil.checkSeedHashes(seedHash_, ThetaUtil.computeSeedHash(seed)); //check for seed hash conflict
maxLgArrLongs_ = 0;
}
} else { //compute & store seedHash
wmem_ = null;
maxLgArrLongs_ = 0;
seedHash_ = ThetaUtil.computeSeedHash(seed);
}
}
/**
* Factory: Construct a new Intersection target on the java heap.
* Called by SetOperationBuilder, test.
*
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Seed</a>
* @return a new IntersectionImpl on the Java heap
*/
static IntersectionImpl initNewHeapInstance(final long seed) {
final boolean dstMemFlag = false;
final boolean readOnly = false;
final IntersectionImpl impl = new IntersectionImpl(null, seed, dstMemFlag, readOnly);
impl.hardReset();
return impl;
}
/**
* Factory: Construct a new Intersection target direct to the given destination Memory.
* Called by SetOperationBuilder, test.
*
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Seed</a>
* @param dstMem destination Memory
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a new IntersectionImpl that may be off-heap
*/
static IntersectionImpl initNewDirectInstance(final long seed, final WritableMemory dstMem) {
//Load Preamble
//Pre0
dstMem.clear(0, CONST_PREAMBLE_LONGS << 3);
insertPreLongs(dstMem, CONST_PREAMBLE_LONGS); //RF not used = 0
insertSerVer(dstMem, SER_VER);
insertFamilyID(dstMem, Family.INTERSECTION.getID());
//lgNomLongs not used by Intersection
//lgArrLongs set by hardReset
//flags are already 0: bigEndian = readOnly = compact = ordered = empty = false;
//seedHash loaded and checked in IntersectionImpl constructor
//Pre1
//CurCount set by hardReset
insertP(dstMem, (float) 1.0); //not used by intersection
//Pre2
//thetaLong set by hardReset
//Initialize
final boolean dstMemFlag = true;
final boolean readOnly = false;
final IntersectionImpl impl = new IntersectionImpl(dstMem, seed, dstMemFlag, readOnly);
impl.hardReset();
return impl;
}
/**
* Factory: Heapify an intersection target from a Memory image containing data.
* @param srcMem The source Memory object.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return a IntersectionImpl instance on the Java heap
*/
static IntersectionImpl heapifyInstance(final Memory srcMem, final long seed) {
final boolean dstMemFlag = false;
final boolean readOnly = false;
final IntersectionImpl impl = new IntersectionImpl(null, seed, dstMemFlag, readOnly);
memChecks(srcMem);
//Initialize
impl.lgArrLongs_ = extractLgArrLongs(srcMem);
impl.curCount_ = extractCurCount(srcMem);
impl.thetaLong_ = extractThetaLong(srcMem);
impl.empty_ = (extractFlags(srcMem) & EMPTY_FLAG_MASK) > 0;
if (!impl.empty_) {
if (impl.curCount_ > 0) {
impl.hashTable_ = new long[1 << impl.lgArrLongs_];
srcMem.getLongArray(CONST_PREAMBLE_LONGS << 3, impl.hashTable_, 0, 1 << impl.lgArrLongs_);
}
}
return impl;
}
/**
* Factory: Wrap an Intersection target around the given source WritableMemory containing
* intersection data.
* @param srcMem The source WritableMemory image.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @param readOnly True if memory is to be treated as read only
* @return a IntersectionImpl that wraps a source WritableMemory that contains an Intersection image
*/
static IntersectionImpl wrapInstance(
final WritableMemory srcMem,
final long seed,
final boolean readOnly) {
final boolean dstMemFlag = false;
final IntersectionImpl impl = new IntersectionImpl(srcMem, seed, dstMemFlag, readOnly);
memChecks(srcMem);
impl.lgArrLongs_ = extractLgArrLongs(srcMem);
impl.curCount_ = extractCurCount(srcMem);
impl.thetaLong_ = extractThetaLong(srcMem);
impl.empty_ = (extractFlags(srcMem) & EMPTY_FLAG_MASK) > 0;
return impl;
}
@Override
public CompactSketch intersect(final Sketch a, final Sketch b, final boolean dstOrdered,
final WritableMemory dstMem) {
if (wmem_ != null && readOnly_) { throw new SketchesReadOnlyException(); }
hardReset();
intersect(a);
intersect(b);
final CompactSketch csk = getResult(dstOrdered, dstMem);
hardReset();
return csk;
}
@Override
public void intersect(final Sketch sketchIn) {
if (sketchIn == null) {
throw new SketchesArgumentException("Intersection argument must not be null.");
}
if (wmem_ != null && readOnly_) { throw new SketchesReadOnlyException(); }
if (empty_ || sketchIn.isEmpty()) { //empty rule
//Because of the def of null above and the Empty Rule (which is OR), empty_ must be true.
//Whatever the current internal state, we make our local empty.
resetToEmpty();
return;
}
ThetaUtil.checkSeedHashes(seedHash_, sketchIn.getSeedHash());
//Set minTheta
thetaLong_ = min(thetaLong_, sketchIn.getThetaLong()); //Theta rule
empty_ = false;
if (wmem_ != null) {
insertThetaLong(wmem_, thetaLong_);
clearEmpty(wmem_); //false
}
// The truth table for the following state machine. MinTheta is set above.
// Incoming sketch is not null and not empty, but could have 0 count and Theta < 1.0
// Case curCount sketchInEntries | Actions
// 1 <0 0 | First intersect, set curCount = 0; HT = null; minTh; exit
// 2 0 0 | set curCount = 0; HT = null; minTh; exit
// 3 >0 0 | set curCount = 0; HT = null; minTh; exit
// 4 | Not used
// 5 <0 >0 | First intersect, clone SketchIn; exit
// 6 0 >0 | set curCount = 0; HT = null; minTh; exit
// 7 >0 >0 | Perform full intersect
final int sketchInEntries = sketchIn.getRetainedEntries(true);
//states 1,2,3,6
if (curCount_ == 0 || sketchInEntries == 0) {
curCount_ = 0;
if (wmem_ != null) { insertCurCount(wmem_, 0); }
hashTable_ = null; //No need for a HT. Don't bother clearing mem if valid
} //end of states 1,2,3,6
// state 5
else if (curCount_ < 0 && sketchInEntries > 0) {
curCount_ = sketchIn.getRetainedEntries(true);
final int requiredLgArrLongs = minLgHashTableSize(curCount_, ThetaUtil.REBUILD_THRESHOLD);
final int priorLgArrLongs = lgArrLongs_; //prior only used in error message
lgArrLongs_ = requiredLgArrLongs;
if (wmem_ != null) { //Off heap, check if current dstMem is large enough
insertCurCount(wmem_, curCount_);
insertLgArrLongs(wmem_, lgArrLongs_);
if (requiredLgArrLongs <= maxLgArrLongs_) {
wmem_.clear(CONST_PREAMBLE_LONGS << 3, 8 << lgArrLongs_); //clear only what required
}
else { //not enough space in dstMem
final int requiredBytes = (8 << requiredLgArrLongs) + 24;
final int givenBytes = (8 << priorLgArrLongs) + 24;
throw new SketchesArgumentException(
"Insufficient internal Memory space: " + requiredBytes + " > " + givenBytes);
}
}
else { //On the heap, allocate a HT
hashTable_ = new long[1 << lgArrLongs_];
}
moveDataToTgt(sketchIn);
} //end of state 5
//state 7
else if (curCount_ > 0 && sketchInEntries > 0) {
//Sets resulting hashTable, curCount and adjusts lgArrLongs
performIntersect(sketchIn);
} //end of state 7
else {
assert false : "Should not happen";
}
}
@Override
public CompactSketch getResult(final boolean dstOrdered, final WritableMemory dstMem) {
if (curCount_ < 0) {
throw new SketchesStateException(
"Calling getResult() with no intervening intersections would represent the infinite set, "
+ "which is not a legal result.");
}
long[] compactCache;
final boolean srcOrdered, srcCompact;
if (curCount_ == 0) {
compactCache = new long[0];
srcCompact = true;
srcOrdered = false; //hashTable, even tho empty
return CompactOperations.componentsToCompact(
thetaLong_, curCount_, seedHash_, empty_, srcCompact, srcOrdered, dstOrdered,
dstMem, compactCache);
}
//else curCount > 0
final long[] hashTable;
if (wmem_ != null) {
final int htLen = 1 << lgArrLongs_;
hashTable = new long[htLen];
wmem_.getLongArray(CONST_PREAMBLE_LONGS << 3, hashTable, 0, htLen);
} else {
hashTable = hashTable_;
}
compactCache = compactCachePart(hashTable, lgArrLongs_, curCount_, thetaLong_, dstOrdered);
srcCompact = true;
srcOrdered = dstOrdered;
return CompactOperations.componentsToCompact(
thetaLong_, curCount_, seedHash_, empty_, srcCompact, srcOrdered, dstOrdered,
dstMem, compactCache);
}
@Override
public boolean hasMemory() {
return wmem_ != null;
}
@Override
public boolean hasResult() {
return hasMemory() ? wmem_.getInt(RETAINED_ENTRIES_INT) >= 0 : curCount_ >= 0;
}
@Override
public boolean isDirect() {
return hasMemory() ? wmem_.isDirect() : false;
}
@Override
public boolean isSameResource(final Memory that) {
return hasMemory() ? wmem_.isSameResource(that) : false;
}
@Override
public void reset() {
hardReset();
}
@Override
public byte[] toByteArray() {
final int preBytes = CONST_PREAMBLE_LONGS << 3;
final int dataBytes = curCount_ > 0 ? 8 << lgArrLongs_ : 0;
final byte[] byteArrOut = new byte[preBytes + dataBytes];
if (wmem_ != null) {
wmem_.getByteArray(0, byteArrOut, 0, preBytes + dataBytes);
}
else {
final WritableMemory memOut = WritableMemory.writableWrap(byteArrOut);
//preamble
memOut.putByte(PREAMBLE_LONGS_BYTE, (byte) CONST_PREAMBLE_LONGS); //RF not used = 0
memOut.putByte(SER_VER_BYTE, (byte) SER_VER);
memOut.putByte(FAMILY_BYTE, (byte) Family.INTERSECTION.getID());
memOut.putByte(LG_NOM_LONGS_BYTE, (byte) 0); //not used
memOut.putByte(LG_ARR_LONGS_BYTE, (byte) lgArrLongs_);
if (empty_) { memOut.setBits(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK); }
else { memOut.clearBits(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK); }
memOut.putShort(SEED_HASH_SHORT, seedHash_);
memOut.putInt(RETAINED_ENTRIES_INT, curCount_);
memOut.putFloat(P_FLOAT, (float) 1.0);
memOut.putLong(THETA_LONG, thetaLong_);
//data
if (curCount_ > 0) {
memOut.putLongArray(preBytes, hashTable_, 0, 1 << lgArrLongs_);
}
}
return byteArrOut;
}
//restricted
/**
* Gets the number of retained entries from this operation. If negative, it is interpreted
* as the infinite <i>Universal Set</i>.
*/
@Override
int getRetainedEntries() {
return curCount_;
}
@Override
boolean isEmpty() {
return empty_;
}
@Override
long[] getCache() {
if (wmem_ == null) {
return hashTable_ != null ? hashTable_ : new long[0];
}
//Direct
final int arrLongs = 1 << lgArrLongs_;
final long[] outArr = new long[arrLongs];
wmem_.getLongArray(CONST_PREAMBLE_LONGS << 3, outArr, 0, arrLongs);
return outArr;
}
@Override
short getSeedHash() {
return seedHash_;
}
@Override
long getThetaLong() {
return thetaLong_;
}
private void performIntersect(final Sketch sketchIn) {
// curCount and input data are nonzero, match against HT
assert curCount_ > 0 && !empty_;
final long[] hashTable;
if (wmem_ != null) {
final int htLen = 1 << lgArrLongs_;
hashTable = new long[htLen];
wmem_.getLongArray(CONST_PREAMBLE_LONGS << 3, hashTable, 0, htLen);
} else {
hashTable = hashTable_;
}
//allocate space for matching
final long[] matchSet = new long[ min(curCount_, sketchIn.getRetainedEntries(true)) ];
int matchSetCount = 0;
final boolean isOrdered = sketchIn.isOrdered();
final HashIterator it = sketchIn.iterator();
while (it.next()) {
final long hashIn = it.get();
if (hashIn < thetaLong_) {
final int foundIdx = hashSearch(hashTable, lgArrLongs_, hashIn);
if (foundIdx != -1) {
matchSet[matchSetCount++] = hashIn;
}
} else {
if (isOrdered) { break; } // early stop
}
}
//reduce effective array size to minimum
curCount_ = matchSetCount;
lgArrLongs_ = minLgHashTableSize(matchSetCount, ThetaUtil.REBUILD_THRESHOLD);
if (wmem_ != null) {
insertCurCount(wmem_, matchSetCount);
insertLgArrLongs(wmem_, lgArrLongs_);
wmem_.clear(CONST_PREAMBLE_LONGS << 3, 8 << lgArrLongs_); //clear for rebuild
} else {
Arrays.fill(hashTable_, 0, 1 << lgArrLongs_, 0L); //clear for rebuild
}
if (curCount_ > 0) {
moveDataToTgt(matchSet, matchSetCount); //move matchSet to target
} else {
if (thetaLong_ == Long.MAX_VALUE) {
empty_ = true;
}
}
}
private void moveDataToTgt(final long[] arr, final int count) {
final int arrLongsIn = arr.length;
int tmpCnt = 0;
if (wmem_ != null) { //Off Heap puts directly into mem
final int preBytes = CONST_PREAMBLE_LONGS << 3;
final int lgArrLongs = lgArrLongs_;
final long thetaLong = thetaLong_;
for (int i = 0; i < arrLongsIn; i++ ) {
final long hashIn = arr[i];
if (continueCondition(thetaLong, hashIn)) { continue; }
hashInsertOnlyMemory(wmem_, lgArrLongs, hashIn, preBytes);
tmpCnt++;
}
} else { //On Heap. Assumes HT exists and is large enough
for (int i = 0; i < arrLongsIn; i++ ) {
final long hashIn = arr[i];
if (continueCondition(thetaLong_, hashIn)) { continue; }
hashInsertOnly(hashTable_, lgArrLongs_, hashIn);
tmpCnt++;
}
}
assert tmpCnt == count : "Intersection Count Check: got: " + tmpCnt + ", expected: " + count;
}
private void moveDataToTgt(final Sketch sketch) {
int count = sketch.getRetainedEntries();
int tmpCnt = 0;
if (wmem_ != null) { //Off Heap puts directly into mem
final int preBytes = CONST_PREAMBLE_LONGS << 3;
final int lgArrLongs = lgArrLongs_;
final long thetaLong = thetaLong_;
HashIterator it = sketch.iterator();
while (it.next()) {
final long hash = it.get();
if (continueCondition(thetaLong, hash)) { continue; }
hashInsertOnlyMemory(wmem_, lgArrLongs, hash, preBytes);
tmpCnt++;
}
} else { //On Heap. Assumes HT exists and is large enough
HashIterator it = sketch.iterator();
while (it.next()) {
final long hash = it.get();
if (continueCondition(thetaLong_, hash)) { continue; }
hashInsertOnly(hashTable_, lgArrLongs_, hash);
tmpCnt++;
}
}
assert tmpCnt == count : "Intersection Count Check: got: " + tmpCnt + ", expected: " + count;
}
private void hardReset() {
resetCommon();
if (wmem_ != null) {
insertCurCount(wmem_, -1); //Universal Set
clearEmpty(wmem_); //false
}
curCount_ = -1; //Universal Set
empty_ = false;
}
private void resetToEmpty() {
resetCommon();
if (wmem_ != null) {
insertCurCount(wmem_, 0);
setEmpty(wmem_); //true
}
curCount_ = 0;
empty_ = true;
}
private void resetCommon() {
if (wmem_ != null) {
if (readOnly_) { throw new SketchesReadOnlyException(); }
wmem_.clear(CONST_PREAMBLE_LONGS << 3, 8 << ThetaUtil.MIN_LG_ARR_LONGS);
insertLgArrLongs(wmem_, ThetaUtil.MIN_LG_ARR_LONGS);
insertThetaLong(wmem_, Long.MAX_VALUE);
}
lgArrLongs_ = ThetaUtil.MIN_LG_ARR_LONGS;
thetaLong_ = Long.MAX_VALUE;
hashTable_ = null;
}
}