Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ public static FrequentLongsSketch getInstance(final String string) {
"Possible Corruption: Incorrect # of tokens: " + numTokens
+ ", numActive: " + numActive);
}
if (lgCur < LG_MIN_MAP_SIZE) {
throw new SketchesArgumentException(
"Possible Corruption: Map length must be at least " + (1 << LG_MIN_MAP_SIZE) + ": "
+ tokens[STR_PREAMBLE_TOKENS + 1]);
}
final long maxActive = (long) ((1L << lgCur) * ReversePurgeLongHashMap.getLoadFactor());
if ((numActive < 0) || (numActive > maxActive)) {
throw new SketchesArgumentException(
"Possible Corruption: numActive exceeds map capacity: " + numActive);
}

final FrequentLongsSketch sketch = new FrequentLongsSketch(lgMax, lgCur);
sketch.streamWeight = streamWt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,37 @@ public void checkStringDeserEmptyFlagWithStreamLength() {
FrequentLongsSketch.getInstance(s);
}

@Test(expectedExceptions = SketchesArgumentException.class, timeOut = 5000)
public void checkStringDeserMapLengthTooSmall() {
final String s = "1," //serVer
+ "10," //FamID
+ "3," //lgMaxMapSz
+ "5," //Empty Flag
+ "0," //stream Len: empty
+ "0," //error offset
+ "0," //numActive
+ "2,"; //curMapLen ... corrupted, below the minimum of 8
final FrequentLongsSketch fls = FrequentLongsSketch.getInstance(s);
fls.update(1);
fls.update(2);
fls.update(3);
}

@Test(expectedExceptions = SketchesArgumentException.class, timeOut = 5000)
public void checkStringDeserNumActiveExceedsMapCapacity() {
final StringBuilder sb = new StringBuilder();
sb.append("1,") //serVer
.append("10,") //FamID
.append("3,") //lgMaxMapSz
.append("0,") //Empty Flag = false
.append("9,") //stream Len
.append("0,") //error offset
.append("9,") //numActive ... corrupted, more than the map can hold
.append("8,"); //curMapLen
for (int i = 1; i <= 9; i++) { sb.append(i).append(",1,"); }
FrequentLongsSketch.getInstance(sb.toString());
}

@Test
public void checkGetEpsilon() {
assertEquals(FrequentLongsSketch.getEpsilon(1024), 3.5 / 1024, 0.0);
Expand Down