1.0.2 • Published 9 years ago

hll-native v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Native HyperLogLog for node.js

See http://en.wikipedia.org/wiki/HyperLogLog.

Based on https://github.com/avz/hll.

Example

var HLL = require('hll-native').HLL;

var tries = 5;

for(var n = 0; n < tries; n++) {
	var start = Date.now();
	var o = {};

	var obj = new HLL(20);

	for(var i = 0; i < 10000000; i++) {
		obj.add('hello_' + i);
	}

	console.log(
		'[' + (n + 1) + ' / ' + tries + ']',
		'Approximated set size:', obj.count() + '.',
		'Elapsed time:', Date.now() - start, 'ms'
	);
}
[1 / 5] Approximated set size: 10000341. Elapsed time: 2142 ms
[2 / 5] Approximated set size: 10000341. Elapsed time: 2133 ms
[3 / 5] Approximated set size: 10000341. Elapsed time: 2142 ms
[4 / 5] Approximated set size: 10000341. Elapsed time: 2121 ms
[5 / 5] Approximated set size: 10000341. Elapsed time: 2118 ms

Memory usage and error values

bitssize (bytes)standard error
41626.00%
53218.38%
66413.00%
71289.19%
82566.50%
95124.60%
1010243.25%
1120482.30%
1240961.62%
1381921.15%
14163840.81%
15327680.57%
16655360.41%
171310720.29%
182621440.20%
195242880.14%
2010485760.10%

Prototype

/**
 * Create new HyperLogLog storage with specified size and standard error.
 *
 * Memory usage for storage calculated as (1 << bits) bytes.
 * Standard error described in table above
 *
 * @param {number} bits
 */
var HLL = function(bits) {};

/**
 * Add key to storage
 * @param {string} key
 */
HLL.prototype.add = function(key) {};

/**
 * Get approximated set size with selected standard error
 * @returns {number}
 */
HLL.prototype.count = function() {};