spacesaver-js

0.6.4 • Public • Published

spacesaver-js

Estimate Top-k elements in data stream using SpaceSaver algorithm. The project use Redis as the backend. Note that this project is being actively developed. If you discover an issue, please fork or submit a ticket describing the problem.

Installation

npm install spacesaver-js

Example usage

var SpaceSaver = require('./lib/');
var k = 100;
var spacesaver = new SpaceSaver(k);
var leaderboard = 'top-news-sites';
var members = ['www.nytimes.com', 'www.cnn.com', 'www.huffpo.com'];
spacesaver.add(leaderboad, members)
    .increment(function(e, res) {
        // fetch the leaders
        spacesaver.leaders(leaderboard, k, function(e, res) {
            console.log(res);
        })
    });
// news - top k
{ 'www.nytmes.com': '240988',
  'www.yahoo.com': '240849',
  'www.google.com': '240368',
  'www.cnn.com': '170723',
  'http://www.tumblr.com': '10000' 
}
 
// social - top 1 of k
{ 
    'www.twitter.com': '170723' 
}

Testing

npm test

TODO

Test is broken since the switch to support internal queues. Prior to this, you needed to add a member one at a time. Now you can pass a collection of memebers to increment!

Contribution

Just fork and issue a pull request :-)

install

npm i spacesaver-js

Downloadsweekly downloads

1

version

0.6.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability