npm

Share private packages across your team with npm Orgs, now with simplified billing via the aws marketplace!Learn more »

cmm-stream

0.9.0 • Public • Published

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 (default 10).
  • depth - the depth of the table. Higher values reduce the probability of large frequency error (default 10).
  • seed - the seed integer for the hash functions (default 42).
  • hashType - which hashing algorithm to use on the values. Can be 'murmur' or any algorithm supported by crypto.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.

install

npm i cmm-stream

Downloadsweekly downloads

8

version

0.9.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability