我一直在試圖實現我自己的(簡單)布隆過濾器,但我堅持哈希,我理解多次散列項目和填充位數組與索引的概念。我使用1種散列算法(我嘗試過FNV,murmurhash,現在farmhash)和各種子(基於當前的納秒)。但是,我發現在我的散列中有大量的衝突。布隆過濾器散列返回太多的碰撞
我必須做一些錯誤的,我通過以下的information here和設置種子等量計算k
功能。
任何幫助將是偉大的,謝謝。
const farmhash = require('farmhash');
class BloomFilter {
\t constructor(items, input)
\t {
\t \t const BITS_PER_ITEM = 15; //~0.1% false positive rate
\t \t this.m = Buffer.alloc(items.length * BITS_PER_ITEM); // setup bit array
\t \t this.k = Math.ceil(BITS_PER_ITEM * 0.7); // amount of hash functions we need to use
\t \t this.seeds = [];
\t \t this.input = input;
\t \t this.items = items;
\t \t this.setSeeds();
\t \t this.insertItems();
\t }
\t get time()
\t {
\t \t let hrTime = process.hrtime()
\t \t return hrTime[1];
\t }
\t setSeeds()
\t {
\t \t for(let i = 0; i <= this.k; i++) this.seeds.push(this.time);
\t }
\t
\t insertItems()
\t {
\t \t console.log('Total buffer size: ' + this.m.length);
\t \t let collisions = 0;
\t \t this.items.forEach(value => { \t \t \t
\t \t \t this.getBufferIndices(value).map(index => {
\t \t \t \t if(this.m[index] === 1) collisions++;
\t \t \t \t this.m[index] = 1;
\t \t \t });
\t \t });
\t \t console.log('Total collisions: ' + collisions);
\t }
\t getBufferIndices(value)
\t {
\t \t let indicies = [];
\t \t this.seeds.forEach(seed => indicies.push(farmhash.hash32WithSeed(value, seed) % this.m.length));
\t \t return indicies;
\t }
}
module.exports = BloomFilter;
請在您的問題中發佈代碼,而不僅僅是當前版本的鏈接。 – Bergi
@Bergi我的不好,固定 –