-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from mcollina/fix-depth-without-basic-keys
Fixed an edge case where deep patterns without a key are not checked.
- Loading branch information
Showing
4 changed files
with
81 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,55 @@ | ||
'use strict' | ||
|
||
var BloomFilter = require('bloomfilter').BloomFilter | ||
var deepSort = require('./deepSort') | ||
var genKeys = require('./genKeys') | ||
var deepMatch = require('./deepMatch') | ||
|
||
function Bucket () { | ||
function Bucket (isDeep) { | ||
this.filter = new BloomFilter( | ||
32 * 256, // number of bits to allocate. | ||
16 // number of hash functions. | ||
) | ||
this.data = [] | ||
this.isDeep = isDeep | ||
} | ||
|
||
Bucket.prototype.add = function (set) { | ||
genKeys(set.pattern).forEach(addPatterns, this) | ||
this.data.push(set) | ||
if (this.isDeep) { | ||
this.data.sort(deepSort) | ||
} | ||
return this | ||
} | ||
|
||
function addPatterns (toAdd) { | ||
this.filter.add(toAdd) | ||
} | ||
|
||
Bucket.prototype.remove = function (pattern, payload) { | ||
var foundPattern = false | ||
var data = this.data | ||
|
||
for (var i = 0; i < data.length; i++) { | ||
if (deepMatch(pattern, data[i].pattern)) { | ||
if (payload === null || payload === data[i].payload) { | ||
data.splice(i, 1) | ||
foundPattern = true | ||
|
||
// to remove all occurences | ||
this.remove(pattern, payload) | ||
break | ||
} | ||
} | ||
} | ||
|
||
return foundPattern | ||
} | ||
|
||
Bucket.prototype.forEach = function (func, that) { | ||
this.data.forEach(func, that) | ||
return this | ||
} | ||
|
||
module.exports = Bucket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters