Registry / testing / updatable-priority-queue

updatable-priority-queue

JSON →
library0.0.1jsnpmunverified

A generic priority queue implementation based on a binary heap with an efficient updateKey operation, version 0.0.1. Release cadence is currently unknown as it's a new package. Key differentiator vs other priority queues: it supports updating the key of an element after insertion, which is essential for algorithms like Dijkstra's or A* pathfinding where priorities change incrementally. Built primarily for the jKstra graph library but generally useful.

npm install updatable-priority-queue
INSTALL
IMPORT
SIG · UPDATABLE-PRIORITY
U
updatable-priority-queue
testingjavascriptv0.0.1
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.

default
import PriorityQueue from 'updatable-priority-queue'
const PriorityQueue = require('updatable-priority-queue')
ESM export only; the module uses ES modules, so require() will not work.
PriorityQueue
import PriorityQueue from 'updatable-priority-queue'
const { PriorityQueue } = require('updatable-priority-queue')
The package exports a single default class; named destructuring is not possible.
type PriorityQueue
import type PriorityQueue from 'updatable-priority-queue'
import { PriorityQueue } from 'updatable-priority-queue'
TypeScript users should use import type for type-only imports.

Demonstrates basic usage: insert, peek, pop, and updateKey operations on the priority queue.

import PriorityQueue from 'updatable-priority-queue'; // Create a priority queue const pq = new PriorityQueue(); // Insert items with keys pq.insert('task1', 10); pq.insert('task2', 5); pq.insert('task3', 20); // Peek at the highest priority item (smallest key) console.log(pq.peek()); // { item: 'task2', key: 5 } // Pop the highest priority item console.log(pq.pop()); // { item: 'task2', key: 5 } console.log(pq.pop()); // { item: 'task1', key: 10 } // Update an item's key pq.insert('task4', 15); pq.updateKey('task4', 2); // now 'task4' has highest priority console.log(pq.peek()); // { item: 'task4', key: 2 }
Debug
Known issues
gotchaThe `updateKey` method expects the exact item reference (or equality via ===) that was inserted. Using a different object with the same value will not update.
fix
Store the same object reference or use primitive values that can be compared with ===.
affects: >=0.0.0
gotchaThe queue does not handle duplicate items; if the same item is inserted twice, undefined behavior may occur when updating or popping.
fix
Ensure each item is unique before insertion, or check if the item already exists (though no contains() method).
affects: >=0.0.0
gotchaThere is no method to check if an item exists in the queue (e.g., contains()), making it easy to accidentally insert duplicates.
fix
Manually track items with a Set or Map, or extend the queue with a contains() method.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: PriorityQueue is not a constructor
Using CommonJS require() on an ES module.
fix
Use import PriorityQueue from 'updatable-priority-queue'; or use dynamic import in CommonJS.
undefined is not an object (evaluating 'pq.pop')
Queue may not have been instantiated correctly, or the import failed silently.
fix
Check import statement and ensure the module is loaded correctly; use default import.
Error: updateKey called on unknown item
The item passed to updateKey was not previously inserted or does not match by reference.
fix
Ensure that the item you pass to updateKey is the exact same object/primitive that was inserted.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
updatable-priority-queue — npm install updatable-priority-queue · libregistry