A binary heap (priority queue) implementation in CoffeeScript/JavaScript, ported from Python's heapq module. Current stable version is 0.2.7 (last released in 2013). No release cadence; maintenance-only mode. Key differentiator: simple API with both instance methods (push, pop, peek) and static methods for arrays, plus nlargest/nsmallest utilities. Alternatives like `flatqueue` or `tinyqueue` may offer better performance or modern features.
npm install heapNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a min-heap using custom compare function, pushes elements, pops the smallest, and uses static nlargest to find top 3 from an array.
Check heap.empty() before calling heap.pop() or handle undefined gracefully.
Be aware that heapify(array) changes the array directly. Clone first if needed.
Consider using an alternative like tinyqueue or flatqueue which are more modern and maintained.
Use `function cmp(a, b) { return a - b; }` for min-heap, not `function cmp(a, b) { return a < b; }`.Create an instance first: var heap = new Heap(); then use heap.push(item);
In browser, use a script tag to include the heap.js file. In Node ESM, use createRequire or switch to an alternative package.
Ensure you are using require('heap') which returns the Heap class, and check package version supports nlargest/nsmallest (available since 0.2.0).No dependency data recorded yet.