Registry / storage / priority-queue-typed

priority-queue-typed

JSON →
library2.6.0jsnpmunverified

A standalone binary heap-based priority queue with min/max modes, part of the data-structure-typed collection. Version 2.6.0 is the latest stable release, published under a weekly cadence. Ships TypeScript types and supports both ES modules and CommonJS. Differentiators include configurable comparators, heapify static method, clone, DFS traversal, and sort. Lightweight (<5 KB min+gzip) and suitable for scheduling, graph algorithms, and triage systems.

npm install priority-queue-typed
INSTALL
IMPORT
SIG · PRIORITY-QUEUE-TYP
P
priority-queue-typed
storagejavascriptv2.6.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.

PriorityQueue
import { PriorityQueue } from 'priority-queue-typed'
const PriorityQueue = require('priority-queue-typed')
ESM-only since v2. Use dynamic import() for CommonJS projects, or ensure your project is configured for ESM.
MinPriorityQueue
import { MinPriorityQueue } from 'priority-queue-typed'
import MinPriorityQueue from 'priority-queue-typed'
MinPriorityQueue is a named export, not a default export.
MaxPriorityQueue
import { PriorityQueue } from 'priority-queue-typed'; const maxPQ = new PriorityQueue({comparator: (a,b) => b - a})
import { MaxPriorityQueue } from 'priority-queue-typed'
MaxPriorityQueue is not exported as a separate class. Use PriorityQueue with reversed comparator.

Demonstrates PriorityQueue constructor with comparator, dynamic add/poll/peek, MinPriorityQueue shorthand, and static heapify method.

import { PriorityQueue, MinPriorityQueue } from 'priority-queue-typed'; const pq = new PriorityQueue<number>({ nodes: [3, 1, 4, 1, 5, 9], comparator: (a, b) => a - b }); console.log(pq.peek()); // 1 pq.add(2); console.log(pq.poll()); // 1 console.log(pq.toArray()); // [2, 3, 4, 5, 9] // Using MinPriorityQueue shorthand const minPQ = new MinPriorityQueue<number>(); minPQ.add(10); minPQ.add(5); console.log(minPQ.peek()); // 5 // Heapify static method const heapified = PriorityQueue.heapify({ nodes: [7, 2, 9], comparator: (a, b) => a - b }); console.log(heapified.toArray()); // [2, 7, 9]
Debug
Known issues
breakingThe import path and export style changed in v2.0.0 – ESM only, named exports.
fix
Use import { PriorityQueue } from 'priority-queue-typed'; instead of require or default import.
affects: >=2.0.0
deprecatedThe class 'MaxPriorityQueue' is removed in v2.0.0. Use PriorityQueue with reversed comparator.
fix
new PriorityQueue({ comparator: (a,b) => b - a })
affects: >=2.0.0
gotchaThe constructor does not accept a plain array directly. You must wrap it in an object with nodes key.
fix
new PriorityQueue({ nodes: [1,2,3], comparator: ... })
affects: >=1.0.0
gotchaComparator must be provided. No default comparator exists.
fix
Always pass a comparator function in the options object.
affects: >=1.0.0
gotchaThe `add` method (lowercase) is used instead of `push` or `enqueue`.
fix
Use pq.add(element) to insert.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Attempting to use CommonJS require with an ESM-only package.
fix
Switch to import syntax or use dynamic import: const { PriorityQueue } = await import('priority-queue-typed');
Error: comparator is required
Constructor called without comparator option.
fix
Pass comparator: (a,b) => a - b for min-heap or b - a for max-heap.
TypeError: pq.push is not a function
Using push() instead of add().
fix
Use pq.add(value) or pq.offer(value) (offer is an alias).
Upgrade
Version history
2.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
16
Resources
priority-queue-typed — npm install priority-queue-typed · libregistry