forked from duckduckgo/jsbloom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.txt
44 lines (43 loc) · 1.28 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
> const JSBloom = require('./bloom.js')
undefined
> const filterA = JSBloom(40000, 0.000001)
undefined
> strGenerator = function () {return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); }
[Function: generator]
> const strArr = []
undefined
> for (let i = 0; i < 40000; i++) { strArr.push(strGenerator()); }
40000
> strArr.forEach(e => filterA.addEntry(e) )
undefined
> strArr.every(e => filterA.checkEntry(e) )
true
> strArr.push('this is new')
40001
> strArr.every(e => filterA.checkEntry(e) )
false
> filterA.addEntry('this is new')
true
> const dataExport = filterA.exportData()
undefined
> const filterB = JSBloom(40001, 0.001)
undefined
> filterB.importData(dataExport)
undefined
> strArr.every(e => filterB.checkEntry(e) )
true
/**
function *strGeneratorFunc() {
const baseStr = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
const randChar = c => {
let r = Math.random() * 16|0;
let v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
};
while (true) {
yield baseStr.replace(/[xy]/g, randChar);
}
}
const myStrGenObj = strGeneratorFunc()
myStrGenObj.next().value
**/