Skip to content
Draft
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 @@ -730,7 +730,7 @@ Row<T>[] sortItems(final long threshold, final ErrorType errorType) {
final long est = getEstimate(iter.getKey());
final long ub = getUpperBound(iter.getKey());
final long lb = getLowerBound(iter.getKey());
if (ub >= threshold) {
if (ub > threshold) {
final Row<T> row = new Row<>(iter.getKey(), est, ub, lb);
rowList.add(row);
}
Expand All @@ -740,7 +740,7 @@ Row<T>[] sortItems(final long threshold, final ErrorType errorType) {
final long est = getEstimate(iter.getKey());
final long ub = getUpperBound(iter.getKey());
final long lb = getLowerBound(iter.getKey());
if (lb >= threshold) {
if (lb > threshold) {
final Row<T> row = new Row<>(iter.getKey(), est, ub, lb);
rowList.add(row);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ Row[] sortItems(final long threshold, final ErrorType errorType) {
final long est = getEstimate(iter.getKey());
final long ub = getUpperBound(iter.getKey());
final long lb = getLowerBound(iter.getKey());
if (ub >= threshold) {
if (ub > threshold) {
final Row row = new Row(iter.getKey(), est, ub, lb);
rowList.add(row);
}
Expand All @@ -830,7 +830,7 @@ Row[] sortItems(final long threshold, final ErrorType errorType) {
final long est = getEstimate(iter.getKey());
final long ub = getUpperBound(iter.getKey());
final long lb = getLowerBound(iter.getKey());
if (lb >= threshold) {
if (lb > threshold) {
final Row row = new Row(iter.getKey(), est, ub, lb);
rowList.add(row);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void severalItems() {
FrequentItemsSketch.Row<String>[] items = sketch.getFrequentItems(ErrorType.NO_FALSE_POSITIVES);
Assert.assertEquals(items.length, 4);

items = sketch.getFrequentItems(3, ErrorType.NO_FALSE_POSITIVES);
items = sketch.getFrequentItems(2, ErrorType.NO_FALSE_POSITIVES);
Assert.assertEquals(items.length, 1);
Assert.assertEquals(items[0].getItem(), "b");

Expand Down Expand Up @@ -539,4 +539,20 @@ public void checkBinaryDeserInconsistentSizes() {
}
}

@Test
public void checkThresholdIsExclusive() {
// Room for 6 items (0.75 * 8): the 7th distinct item purges all counts of 1, so the max error is 1.
final FrequentItemsSketch<Long> sketch = new FrequentItemsSketch<>(8);
for (long item = 1; item <= 8; item++) {
sketch.update(item);
}
assertEquals(sketch.getMaximumError(), 1);
assertEquals(sketch.getLowerBound(8L), 1);
// Lower bound 1 is not above max error 1, so NO_FALSE_POSITIVES drops item 8.
assertEquals(sketch.getFrequentItems(ErrorType.NO_FALSE_POSITIVES).length, 0);
// Upper bound 2 is above threshold 1 but not above threshold 2.
assertEquals(sketch.getFrequentItems(2, ErrorType.NO_FALSE_NEGATIVES).length, 0);
assertEquals(sketch.getFrequentItems(1, ErrorType.NO_FALSE_NEGATIVES).length, 1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,20 @@ public void checkBinaryDeserActiveItemsBeyondImage() {
catch (final SketchesArgumentException e) { }
}

@Test
public void checkThresholdIsExclusive() {
// Room for 6 items (0.75 * 8): the 7th distinct item purges all counts of 1, so the max error is 1.
final FrequentLongsSketch sketch = new FrequentLongsSketch(8);
for (long item = 1; item <= 8; item++) {
sketch.update(item);
}
assertEquals(sketch.getMaximumError(), 1);
assertEquals(sketch.getLowerBound(8L), 1);
// Lower bound 1 is not above max error 1, so NO_FALSE_POSITIVES drops item 8.
assertEquals(sketch.getFrequentItems(ErrorType.NO_FALSE_POSITIVES).length, 0);
// Upper bound 2 is above threshold 1 but not above threshold 2.
assertEquals(sketch.getFrequentItems(2, ErrorType.NO_FALSE_NEGATIVES).length, 0);
assertEquals(sketch.getFrequentItems(1, ErrorType.NO_FALSE_NEGATIVES).length, 1);
}

}