Registry / testing / max-priority-queue-typed

max-priority-queue-typed

JSON →
library2.6.0jsnpmunverified

A standalone Max Priority Queue data structure with TypeScript support, implemented as part of the data-structure-typed collection. Version 2.6.0 provides a minified bundle of ~5.3 KB. It uses a binary heap and offers typical operations like add, poll, peek, and toArray. The package is actively maintained alongside the larger data-structure-typed library, which includes many other data structures. Key differentiators include a focus on TypeScript-first design, custom comparator support, and detailed API documentation. The package follows a regular release cadence with weekly releases.

npm install max-priority-queue-typed
INSTALL
IMPORT
SIG · MAX-PRIORITY-QUEUE
M
max-priority-queue-typed
testingjavascriptv2.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.

MaxPriorityQueue
import { MaxPriorityQueue } from 'max-priority-queue-typed'
const MaxPriorityQueue = require('max-priority-queue-typed');
The default export is a named export. Since it's a TypeScript library with types, named imports are recommended. For ESM usage, use dynamic import or the ES module build.
heap
import { MaxPriorityQueue } from 'max-priority-queue-typed'
import MaxPriorityQueue from 'max-priority-queue-typed';
There is no default export. Use named import for the class.
type
import type { MaxPriorityQueueOptions } from 'max-priority-queue-typed'
import { MaxPriorityQueueOptions } from 'max-priority-queue-typed';
Type imports should use 'import type' to avoid runtime errors. The options type is available but not exported as a value.

Creates a max priority queue with a custom comparator and demonstrates adding, peeking, and polling elements.

import { MaxPriorityQueue } from 'max-priority-queue-typed'; interface Bid { bidder: string; amount: number; } const auction = new MaxPriorityQueue<Bid>([], { comparator: (a, b) => b.amount - a.amount }); austion.add({ bidder: 'Alice', amount: 100 }); austion.add({ bidder: 'Bob', amount: 250 }); austion.add({ bidder: 'Charlie', amount: 175 }); console.log(auction.peek()?.bidder); // 'Bob' console.log(auction.poll()?.amount); // 250 console.log(auction.peek()?.bidder); // 'Charlie' console.log(auction.size); // 2
Debug
Known issues
breakingThe constructor signature changed in v2.0: the initial elements and options are passed as separate arguments, not as a single object.
fix
Use new MaxPriorityQueue<T>(initialElements?, options?) where options contains comparator and other settings.
affects: <2.0
deprecatedThe 'push' and 'pop' methods were deprecated in v2.0 in favor of 'add' and 'poll'.
fix
Replace calls to .push(element) with .add(element) and .pop() with .poll().
affects: >=2.0
gotchaThe comparator function expects a numeric return (positive, negative, or zero) like Array.sort's comparator. Returning a boolean (true/false) will cause incorrect ordering.
fix
Use a comparator that returns a number, e.g., (a, b) => a - b for min-heap or (a, b) => b - a for max-heap.
affects: >=2.0
Errors
Common errors & fixes
TypeError: MaxPriorityQueue is not a constructor
Using default import instead of named import.
fix
Replace import MaxPriorityQueue from 'max-priority-queue-typed' with import { MaxPriorityQueue } from 'max-priority-queue-typed'.
Module not found: Can't resolve 'max-priority-queue-typed'
The package name is 'max-priority-queue-typed' (with 'typed'), not 'max-priority-queue'.
fix
Install the correct package: npm install max-priority-queue-typed
Property 'poll' does not exist on type 'MaxPriorityQueue<number>'
Attempting to use a method that doesn't exist (e.g., 'pop' was renamed to 'poll').
fix
Use the correct method name: .poll() instead of .pop().
Upgrade
Version history
2.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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