File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change @@ -63,6 +63,16 @@ describe('JSBloom - Bloom Filter', function() {
6363
6464 } ) ;
6565
66+ describe ( 'Duplicate Insertion' , function ( ) {
67+ it ( 'should return true for 2000 added elements' , function ( ) {
68+ for ( var i = test_entries . length - 1 ; i >= 0 ; i -- ) {
69+ assert . equal ( filter . addEntry ( test_entries [ i ] ) , false ) ;
70+ } ;
71+ } ) ;
72+
73+ } ) ;
74+
75+
6676 describe ( 'Non-Existence' , function ( ) {
6777 it ( 'should return false for 1000 non elements' , function ( ) {
6878 var positive = 0 ;
You can’t perform that action at this time.
0 commit comments