Registry / storage / priority-queue

priority-queue

JSON →
library0.2.1jsnpmunverified

A functional, data-oriented priority queue (max-heap) for Node.js, version 0.2.1. Designed to be tiny (~150 lines), pure ES module, and — critically — does not allocate memory at runtime after initial creation. It is a preallocated array-based heap offering queue, dequeue, isEmpty, clear, delete, and list operations. Unlike typical priority queue libraries that allocate dynamically, this one is suited for performance-critical or real-time applications where GC pauses must be avoided. The package is actively maintained and has tests via GitHub Actions.

storage
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.

ESM-only since v0.1.0; CommonJS require() will throw.

import PQ from 'priority-queue'

create is not a named export; it is a method on the default export.

import PQ from 'priority-queue'; const obj = PQ.create()

API is functional, not object-oriented. Methods are on the PQ module, not the queue object.

PQ.queue(obj, 'item', priority)

Create a priority queue, insert items with priorities, and dequeue them in order of descending priority. Shows that dequeue returns undefined when empty.

import PQ from 'priority-queue' const obj = PQ.create(20000) PQ.queue(obj, 'low', 1) PQ.queue(obj, 'high', 10) PQ.queue(obj, 'medium', 5) console.log(PQ.dequeue(obj)) // 'high' console.log(PQ.dequeue(obj)) // 'medium' console.log(PQ.dequeue(obj)) // 'low' console.log(PQ.dequeue(obj)) // undefined
Debug
Known footguns
gotchaThe queue has a fixed maximum size set at creation (default 1000). Inserting more items will exceed capacity and cause undefined behavior or errors.
gotchaThe queue is a max-heap. Items with higher priority are dequeued first. If you need a min-heap (lowest priority first), invert the priority values (e.g., use negative values).
gotchadelete method expects exact reference equality to remove an item. If you pass a different object with same data, it won't be found.
breakingVersion 0.2.0 changed internal structure; PQ.queue now takes (obj, item, priority) instead of (obj, item, priority, ...) previously? Check release notes for exact changes.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
11 hits · last 30 days
gptbot
3
bingbot
1
ahrefsbot
1
amazonbot
1
Resources