ordered-freq-counter
v3.3.3
Published
Ordered frequency counter with top-N queries, built on btree-core.
Maintainers
Readme
ordered-freq-counter
Ordered frequency counter with top-N queries, built on btree-core.
Install
npm install ordered-freq-counterUsage
const OrderedFreqCounter = require('ordered-freq-counter');
const counter = new OrderedFreqCounter();
counter.add('apple');
counter.add('banana');
counter.add('apple');
counter.add('carrot', 3);
counter.get('apple'); // 2
counter.top(2);
// [
// { key: 'carrot', count: 3 },
// { key: 'apple', count: 2 }
// ]
counter.entriesByKey();
// apple, banana, carrot (sorted by key)API
| Method | Description |
| --- | --- |
| add(key, delta?) | Increase count (default +1) |
| get(key) | Current count (0 if missing) |
| has(key) | Whether key exists |
| delete(key) | Remove key |
| top(limit?) | Highest counts first (default 10) |
| entriesByKey() | Entries sorted by key |
| clear() | Reset |
| size | Distinct keys |
License
MIT
