Skip to content

Commit 6bd3af5

Browse files
fix putIfFrequent
1 parent 0319dd5 commit 6bd3af5

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

YASL-Core/src/YASL/AugmentedSketch/CAugmentedSketch.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public CAugmentedSketch(int sz, IItemsCounter<T> counter) {
3434
}
3535

3636
private long putToCounter(T item, long count) {
37-
if (!_heap.isFull()) {
38-
_heap.add(new CasItem<T>(item, count, 0));
39-
return count;
40-
}
41-
4237
final long cnt = _counter.put(item, count);
4338
if (_heap.lowest().Priority() < cnt) {
4439
final CasItem<T> oldMin = _heap.poll();
@@ -57,6 +52,12 @@ public long putIfFrequent(T item, long count) {
5752
_heap.update(item);
5853
return ratted.Priority();
5954
}
55+
56+
if (!_heap.isFull()) {
57+
_heap.add(new CasItem<T>(item, count, 0));
58+
return count;
59+
}
60+
6061
return 0;
6162
}
6263

YASL-Tests/src/Tests/AugmentedSketch/Test_AugmentedSketch.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import YASL.IEstimator;
99
import YASL.IItemsCounter;
1010
import YASL.AugmentedSketch.CAugmentedSketch;
11+
import YASL.AugmentedSketch.IAugmentedSketch;
1112

1213
public class Test_AugmentedSketch {
1314
@Test
@@ -110,4 +111,16 @@ public void counting() {
110111
Assert.assertEquals(1 + 5, est.count(123));
111112
Assert.assertEquals(1 + 8, est.count(321));
112113
}
114+
115+
@Test
116+
public void PIF_IfHeapNotFull() {
117+
final IAugmentedSketch<Integer> est = //
118+
new CAugmentedSketch<Integer>( //
119+
new CasTestHeap(1), //
120+
new CasTestCounter() //
121+
);
122+
123+
est.putIfFrequent(123, 1);
124+
Assert.assertEquals(1, est.count(123));
125+
}
113126
}

0 commit comments

Comments
 (0)