hll-stream
v0.10.0
Published
Stream-based HyperLogLog implementation
Downloads
13
Maintainers
Readme
hll-stream
Pipe in your stream of buffers/strings to get an approximate cardinality (using HyperLogLog).
var Hll = require('hll-stream');
var hll = new Hll(8);
//...
myDataSource.pipe(hll);
hll.on('finish', function() {
console.log(hll.cardinality());
});
Limitations
hll-stream uses 32-bit hash values since node.js won't currently do bit-wise arithmetic on more than 32 bits.
API
Hll(precision, hashType, streamOpts)
Construct a new writable Hll (extends Stream.Writable
).
precision
- number of bits of precision (4-16) (default 4). Memory usage is on the order of 2precision.hashType
- which hashing algorithm to use on the values. Can be any algorithm supported bycrypto.createHash
(default:'sha1'
).streamOpts
- the options to pass along to the stream constructor.
Hll.cardinality()
Compute the approximate cardinality.
Hll.merge(hll)
Merge another Hll with this one. The two Hlls must have the same hashType
and precision
. Returns a new Hll.
hll
- another instance ofhll-stream
to merge with this one.
Hll.export()
Export the Hll's data. Returns an object like:
{
precision: 8,
hashType: 'sha1',
registers: [...]
}
Hll.import(data)
Import Hll data (as exported by export()
). Replaces any pre-existing data.
data
- the data object to import. Should be in the same format as exported byexport()
.