Skip to content

Commit 90442a1

Browse files
author
lrhodes
committed
Improved Javadoc and getStorageBytes() was returning a number that was
16 bytes too large.
1 parent 488d027 commit 90442a1

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/main/java/com/yahoo/sketches/frequencies/LongsSketch.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@
6262
* <p>The hash map starts at a very small size (8 entries), and grows as needed up to the
6363
* specified <i>maxMapSize</i>.</p>
6464
*
65-
* <p>The internal memory space usage of this sketch is 18 * <i>mapSize</i> bytes, plus a small
66-
* constant number of additional bytes. The internal memory space usage of this sketch will never
67-
* exceed 18 * <i>maxMapSize</i> bytes, plus a small constant number of additional bytes.</p>
65+
* <p>At any moment the internal memory space usage of this sketch is 18 * <i>mapSize</i> bytes,
66+
* plus a small constant number of additional bytes. The maximum internal memory space usage of
67+
* this sketch will never exceed 18 * <i>maxMapSize</i> bytes, plus a small constant number of
68+
* additional bytes.</p>
6869
*
6970
* <p><b>Maximum Capacity of the Sketch</b></p>
7071
*
@@ -445,7 +446,7 @@ public int getNumActiveItems() {
445446
*/
446447
public int getStorageBytes() {
447448
if (isEmpty()) { return 8; }
448-
return (6 * 8) + (16 * getNumActiveItems());
449+
return (4 * 8) + (16 * getNumActiveItems());
449450
}
450451

451452
/**
@@ -547,7 +548,7 @@ public byte[] toByteArray() {
547548
preLongs = 1;
548549
outBytes = 8;
549550
} else {
550-
preLongs = Family.FREQUENCY.getMaxPreLongs();
551+
preLongs = Family.FREQUENCY.getMaxPreLongs(); //4
551552
outBytes = (preLongs + (2 * activeItems)) << 3; //2 because both keys and values are longs
552553
}
553554
final byte[] outArr = new byte[outBytes];

src/test/java/com/yahoo/sketches/frequencies/LongsSketchTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,9 @@ public void checkGetFrequentItems1() {
416416
public void checkGetStorageBytes() {
417417
int minSize = 1 << LG_MIN_MAP_SIZE;
418418
LongsSketch fls = new LongsSketch(minSize);
419-
int bytes = fls.getStorageBytes();
420-
assertEquals(bytes, 8);
419+
assertEquals(fls.toByteArray().length, fls.getStorageBytes());
421420
fls.update(1);
422-
bytes = fls.getStorageBytes();
423-
assertEquals(bytes, 64);
421+
assertEquals(fls.toByteArray().length, fls.getStorageBytes());
424422
}
425423

426424
@Test

0 commit comments

Comments
 (0)