Registry / storage / qheap
library1.4.0jsnpmunverified

qheap is a fast binary heap / priority queue library for Node.js (v1.4.0, stable, low release cadence). It supports insert, remove, peek, and heap operations with O(log n) complexity. Compared to alternatives like fastpriorityqueue, qheap offers good performance and a simple API. Primary use cases include scheduling, event loops, and Graph algorithms. The package is pure JavaScript without native bindings, making it portable across platforms.

npm install qheap
INSTALL
IMPORT
SIG · QHEAP
Q
qheap
storagejavascriptv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Heap
✓ const Heap = require('qheap');
✗ import Heap from 'qheap';
This package is CommonJS only; ESM import will fail.
Heap constructor (options)
✓ const h = new Heap({ compar: myCompar });
✗ const h = new Qheap({ compar: myCompar });
The module exports the constructor directly; no named export.
Heap with comparator function
✓ const h = new Heap(myCompar);
✗ const h = new Heap({ compar: myCompar });
If options is a function, it is taken as the comparator function (like compar option).

Create a heap, insert items, remove the smallest, peek at the next, and check length.

const Heap = require('qheap'); const h = new Heap(); h.insert('c'); h.insert('a'); h.insert('b'); console.log(h.remove()); // 'a' console.log(h.peek()); // 'b' console.log(h.length); // 2
Debug
Known issues
gotchalength property is read-only; setting it will cause undefined behavior.
fix
Read length only; do not assign.
affects: *
gotchaDefault comparison uses < (less than). For numbers works as min-heap. To get a max-heap, provide a custom comparBefore or compar function.
fix
Use compar or comparBefore option: new Heap({ comparBefore: (a,b) => a > b })
affects: *
gotchagc() is available but not automatically called; memory may grow unbounded if freeSpace option is not set.
fix
Use gc() manually or enable freeSpace option on construction.
affects: *
Errors
Common errors & fixes
TypeError: heap.remove is not a function
Using wrong import pattern (e.g., import Heap from 'qheap' in ESM).
fix
Use require('qheap') in CommonJS.
TypeError: heap.insert is not a function
Instantiating the heap incorrectly (e.g., new qheap() instead of new Heap()).
fix
Use const Heap = require('qheap'); const h = new Heap();
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
packageqheap ↗
qheap — npm install qheap · libregistry