我在应用程序中使用布隆过滤器来扫描重复项:
var BloomFilter = require('bloom-filter');
var numberOfElements = 30000;
var falsePositiveRate = 0.005;
var filter = BloomFilter.create(numberOfElements, falsePositiveRate);
var workFunction = function(var1, var2) {
var bloomData = new Buffer(var1 + var2, "hex");
if(!filter.contains(bloomData)){
console.log("In the loop, adding the element to the bloom filter now!");
filter.insert(bloomData);
// work with the data and see if I found a needle in the haystack .. if yes, the bloom filter needs a reset !
if (var === "123") {
console.log("Needle found, resetting to fresh filter, new round !");
var filter = BloomFilter.create(numberOfElements, falsePositiveRate); // WRONG HERE but you get the idea!
}
} else {
console.log("This entry is already in the bloom filter !");
}
}
workFunction("1234", "1234");
经过一定数量的回合后,我想重置/清除/更新过滤器,正如您在上面的声明中看到的那样,但这当然会失败,因为此时它仍在使用中。
我如何编写回调或类似的内容来重置过滤器?
谢谢
最佳答案
看起来特定的 Node 模块没有 reset
方法或 API 中的任何类似方法。
此时您似乎可以做两件事。
1.为该存储库提出一个问题,请求此类功能(或编写您自己的 Pull-Request)https://github.com/jasondavies/bloomfilter.js
2.更改 workFunction
的行为以重置过滤器。
var workFunction = function(var1, var2) {
var filter = BloomFilter.create(numberOfElements, falsePositiveRate);
// ...
}
或者类似的东西来重置 iti 自己。
关于javascript - 在 NodeJS 中删除/重置/清除布隆过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32234075/