cmm-stream
v0.9.0
Published
Stream-based count-mean-min sketch
Downloads
5
Maintainers
Readme
##cmm-stream
A stream-based Count-mean-min sketch implementation. Pipe in some strings/buffers to get frequency estimation.
var c = new Cmm(20, 20);
//...
myDataSource.pipe(c);
c.on('finish', function() {
console.log(c.frequency('42'));
console.log(c.frequency('13'));
});
API
Cmm(width, depth, hashType, streamOpts)
Construct a new writable Cmm (extends Stream.Writable
).
width
- the width of the table. Higher values reduce the magnitude of the frequency error (default10
).depth
- the depth of the table. Higher values reduce the probability of large frequency error (default10
).seed
- the seed integer for the hash functions (default42
).hashType
- which hashing algorithm to use on the values. Can be'murmur'
or any algorithm supported bycrypto.createHash
(default:'murmur'
).streamOpts
- the options to pass along to the stream constructor.
Cmm.frequency(value)
Compute the approximate frequency of value
.
Cmm.export()
Export the Cmm data. Returns an object like:
{
width: 10,
depth: 10,
seed: 42,
hashType: 'whirlpool',
total: 100000,
registers: [...]
}
Cmm.import(data)
Import a Cmm data object. Replaces existing data.
Cmm.merge(cmm)
Merge this Cmm with another Cmm, creating a new instance. width
, depth
, seed
, and hashType
must match between the two.