Skip to content

Commit

Permalink
Add ChaoSampling assertion
Browse files Browse the repository at this point in the history
When adding in the impossible set, the new items must always enter the data structure.
  • Loading branch information
gstamatelat committed Aug 20, 2022
1 parent fd47886 commit 1435c8d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/gr/james/sampling/ChaoSampling.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public boolean feed(T item, double weight) {
// The first k items go straight into the A list
if (this.impossible.size() + this.sample.size() < sampleSize) {
assert this.sample.isEmpty();
this.impossible.add(new Weighted<>(item, weight));
final boolean added = this.impossible.add(new Weighted<>(item, weight));
assert added;
return true;
}

Expand Down Expand Up @@ -202,7 +203,8 @@ public boolean feed(T item, double weight) {

if (w >= 1) {
// New item is overweight and will be placed in A
this.impossible.add(new Weighted<>(item, weight));
final boolean added = this.impossible.add(new Weighted<>(item, weight));
assert added;
} else if (w > add) {
// New item is feasible and will be placed in C
this.sample.add(item);
Expand Down

0 comments on commit 1435c8d

Please sign in to comment.