Skip to content

Commit 50231ff

Browse files
committed
addEntry: return false if item was already in set
1 parent bf7dc7a commit 50231ff

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bloom.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ JSBloom.filter = function(items, target_prob) {
4444

4545
var h1 = hashes.djb2(str)
4646
var h2 = hashes.sdbm(str)
47+
var added = false
4748
for (var round = 0; round <= HASH_ROUNDS; round++) {
4849
var new_hash = round == 0 ? h1
4950
: round == 1 ? h2
@@ -54,13 +55,15 @@ JSBloom.filter = function(items, target_prob) {
5455

5556
if (extra_indices != 0 && (bVector[index] & (128 >> (extra_indices - 1))) == 0) {
5657
bVector[index] ^= (128 >> extra_indices - 1);
58+
added = true;
5759
} else if (extra_indices == 0 && (bVector[index] & 1) == 0) {
5860
bVector[index] ^= 1;
61+
added = true;
5962
}
6063

6164
};
6265

63-
return true;
66+
return added;
6467
}
6568

6669
addEntries = function(arr) {

0 commit comments

Comments
 (0)