-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
50 lines (47 loc) · 1.21 KB
/
main.js
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
45
46
47
48
49
50
var HLL = require('./build/Release/hll_native').HLL;
/**
* Create new HyperLogLog storage with specified size and standard error.
*
* Memory usage for storage calculated as (1 << bits) bytes.
*
* Standard error described below
*
* |bits|size (bytes)| error |
* |----|------------|--------|
* | 4 | 16 | 26.00% |
* | 5 | 32 | 18.38% |
* | 6 | 64 | 13.00% |
* | 7 | 128 | 9.19% |
* | 8 | 256 | 6.50% |
* | 9 | 512 | 4.60% |
* | 10 | 1024 | 3.25% |
* | 11 | 2048 | 2.30% |
* | 12 | 4096 | 1.62% |
* | 13 | 8192 | 1.15% |
* | 14 | 16384 | 0.81% |
* | 15 | 32768 | 0.57% |
* | 16 | 65536 | 0.41% |
* | 17 | 131072 | 0.29% |
* | 18 | 262144 | 0.20% |
* | 19 | 524288 | 0.14% |
* | 20 | 1048576 | 0.10% |
*
* @param {number} bits
*/
exports.HLL = function(bits) {
this.hll = new HLL(bits);
};
/**
* Add key to storage
* @param {string} key
*/
exports.HLL.prototype.add = function(key) {
this.hll.add(key);
};
/**
* Get approximated set size with selected standard error, depends on `bits` value
* @returns {number}
*/
exports.HLL.prototype.count = function() {
return this.hll.count();
};