Skip to content

Commit b16605c

Browse files
authored
Merge pull request #656 from apache/touchup_after_merge
touch-up changes mostly to clean up code contributed by others.
2 parents 8dbbc8e + 9e5b51c commit b16605c

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

src/main/java/org/apache/datasketches/theta/CompactSketch.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,61 @@ else if (serVer == 2) {
228228
"Corrupted: Serialization Version " + serVer + " not recognized.");
229229
}
230230

231+
/**
232+
* Wrap takes the sketch image in the given Memory and refers to it directly.
233+
* There is no data copying onto the java heap.
234+
* The wrap operation enables fast read-only merging and access to all the public read-only API.
235+
*
236+
* <p>Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
237+
* been explicitly stored as direct sketches can be wrapped.
238+
* Wrapping earlier serial version sketches will result in a heapify operation.
239+
* These early versions were never designed to "wrap".</p>
240+
*
241+
* <p>Wrapping any subclass of this class that is empty or contains only a single item will
242+
* result in heapified forms of empty and single item sketch respectively.
243+
* This is actually faster and consumes less overall memory.</p>
244+
*
245+
* <p>This method checks if the DEFAULT_UPDATE_SEED was used to create the source Memory image.
246+
* Note that SerialVersion 1 sketches cannot be checked as they don't have a seedHash field,
247+
* so the resulting heapified CompactSketch will be given the hash of DEFAULT_UPDATE_SEED.</p>
248+
*
249+
* @param bytes a byte array image of a Sketch that was created using the DEFAULT_UPDATE_SEED.
250+
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
251+
*
252+
* @return a CompactSketch backed by the given Memory except as above.
253+
*/
231254
public static CompactSketch wrap(final byte[] bytes) {
232255
return wrap(bytes, ThetaUtil.DEFAULT_UPDATE_SEED, false);
233256
}
234-
257+
258+
/**
259+
* Wrap takes the sketch image in the given Memory and refers to it directly.
260+
* There is no data copying onto the java heap.
261+
* The wrap operation enables fast read-only merging and access to all the public read-only API.
262+
*
263+
* <p>Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
264+
* been explicitly stored as direct sketches can be wrapped.
265+
* Wrapping earlier serial version sketches will result in a heapify operation.
266+
* These early versions were never designed to "wrap".</p>
267+
*
268+
* <p>Wrapping any subclass of this class that is empty or contains only a single item will
269+
* result in heapified forms of empty and single item sketch respectively.
270+
* This is actually faster and consumes less overall memory.</p>
271+
*
272+
* <p>This method checks if the given expectedSeed was used to create the source Memory image.
273+
* Note that SerialVersion 1 sketches cannot be checked as they don't have a seedHash field,
274+
* so the resulting heapified CompactSketch will be given the hash of the expectedSeed.</p>
275+
*
276+
* @param bytes a byte array image of a Sketch that was created using the given expectedSeed.
277+
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
278+
* @param expectedSeed the seed used to validate the given Memory image.
279+
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
280+
* @return a CompactSketch backed by the given Memory except as above.
281+
*/
235282
public static CompactSketch wrap(final byte[] bytes, final long expectedSeed) {
236283
return wrap(bytes, expectedSeed, true);
237284
}
238-
285+
239286
private static CompactSketch wrap(final byte[] bytes, final long seed, final boolean enforceSeed) {
240287
final int serVer = bytes[PreambleUtil.SER_VER_BYTE];
241288
final int familyId = bytes[PreambleUtil.FAMILY_BYTE];

src/main/java/org/apache/datasketches/theta/DirectCompactCompressedSketch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public int getCurrentBytes() {
8282

8383
private static final int START_PACKED_DATA_EXACT_MODE = 8;
8484
private static final int START_PACKED_DATA_ESTIMATION_MODE = 16;
85-
85+
8686
@Override
8787
public int getRetainedEntries(final boolean valid) { //compact is always valid
8888
// number of entries is stored using variable length encoding
@@ -132,7 +132,7 @@ long[] getCache() {
132132
final int numEntries = getRetainedEntries();
133133
final long[] cache = new long[numEntries];
134134
int i = 0;
135-
HashIterator it = iterator();
135+
final HashIterator it = iterator();
136136
while (it.next()) {
137137
cache[i++] = it.get();
138138
}

src/main/java/org/apache/datasketches/theta/IntersectionImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,21 +504,21 @@ private void moveDataToTgt(final long[] arr, final int count) {
504504
}
505505

506506
private void moveDataToTgt(final Sketch sketch) {
507-
int count = sketch.getRetainedEntries();
507+
final int count = sketch.getRetainedEntries();
508508
int tmpCnt = 0;
509509
if (wmem_ != null) { //Off Heap puts directly into mem
510510
final int preBytes = CONST_PREAMBLE_LONGS << 3;
511511
final int lgArrLongs = lgArrLongs_;
512512
final long thetaLong = thetaLong_;
513-
HashIterator it = sketch.iterator();
513+
final HashIterator it = sketch.iterator();
514514
while (it.next()) {
515515
final long hash = it.get();
516516
if (continueCondition(thetaLong, hash)) { continue; }
517517
hashInsertOnlyMemory(wmem_, lgArrLongs, hash, preBytes);
518518
tmpCnt++;
519519
}
520520
} else { //On Heap. Assumes HT exists and is large enough
521-
HashIterator it = sketch.iterator();
521+
final HashIterator it = sketch.iterator();
522522
while (it.next()) {
523523
final long hash = it.get();
524524
if (continueCondition(thetaLong_, hash)) { continue; }

src/main/java/org/apache/datasketches/theta/Sketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public String toString(final boolean sketchSummary, final boolean dataDetail, fi
472472
final int w = width > 0 ? width : 8; // default is 8 wide
473473
if (curCount > 0) {
474474
sb.append("### SKETCH DATA DETAIL");
475-
HashIterator it = iterator();
475+
final HashIterator it = iterator();
476476
int j = 0;
477477
while (it.next()) {
478478
final long h = it.get();

src/main/java/org/apache/datasketches/theta/WrappedCompactSketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public byte[] toByteArray() {
136136
long[] getCache() {
137137
final long[] cache = new long[getRetainedEntries()];
138138
int i = 0;
139-
HashIterator it = iterator();
139+
final HashIterator it = iterator();
140140
while (it.next()) {
141141
cache[i++] = it.get();
142142
}

src/test/java/org/apache/datasketches/hll/SizeAndModeTransitions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public void checkHLL8Heap() {
4545
} else {
4646
sk = new HllSketch(lgK, tgtHllType);
4747
}
48-
String type = tgtHllType.toString();
4948
String store = direct ? "Memory" : "Heap";
5049
for (int i = 1; i <= N; i++) {
5150
sk.update(i);

0 commit comments

Comments
 (0)