Skip to content

Commit 0e9b4f3

Browse files
authored
Optimize contains method in bloom filter
Refactor contains method to return early if any hash check fails.
1 parent 79dee79 commit 0e9b4f3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docs/cs-basics/data-structure/bloom-filter.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ public class MyBloomFilter {
130130
public boolean contains(Object value) {
131131
boolean ret = true;
132132
for (SimpleHash f : func) {
133-
ret = ret && bits.get(f.hash(value));
133+
ret = bits.get(f.hash(value));
134+
if(!ret)
135+
return ret;
134136
}
135137
return ret;
136138
}

0 commit comments

Comments
 (0)