Skip to content

Estimate top K elements in data stream using SpaceSaver algorithm. Backed by RedisDB

License

Notifications You must be signed in to change notification settings

krg7880/spacesaver-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 :-)

About

Estimate top K elements in data stream using SpaceSaver algorithm. Backed by RedisDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published