Registry / development / bucket-priority-queue

bucket-priority-queue

JSON →
library2.1.0jsnpmunverified

A TypeScript implementation of the bucket queue data structure, optimized for priority-based item management when the priority key space consists of small positive integers. Version 2.1.0 is the latest stable release, actively maintained. It offers extremely fast enqueue and dequeue operations, outperforming heap-based priority queues in benchmarks, making it ideal for algorithms like Dijkstra's. Ships with full TypeScript type definitions and supports both min and max bucket queues.

npm install bucket-priority-queue
INSTALL
IMPORT
SIG · BUCKET-PRIORITY-QU
B
bucket-priority-queue
developmentjavascriptv2.1.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.

MinBucketQueue
import { MinBucketQueue } from 'bucket-priority-queue'
import MinBucketQueue from 'bucket-priority-queue'
Named export; default import will cause runtime error.
MaxBucketQueue
import { MaxBucketQueue } from 'bucket-priority-queue'
const { MaxBucketQueue } = require('bucket-priority-queue')
Works with both ESM and CJS, but named export syntax is preferred.
Priority
import type { Priority } from 'bucket-priority-queue'
Type export for the priority type (number).

Shows instantiation with initial items, push, pop, peek, size, and clear operations for both MinBucketQueue and MaxBucketQueue.

import { MinBucketQueue, MaxBucketQueue } from 'bucket-priority-queue'; // Create a min bucket queue with initial items const minQueue = new MinBucketQueue<number>([ [10, 2], [20, 1], [30, 3], ]); console.log(minQueue.pop()); // 20 (lowest priority) // Create a max bucket queue const maxQueue = new MaxBucketQueue<string>([ ['a', 1], ['b', 3], ['c', 2], ]); console.log(maxQueue.pop()); // 'b' (highest priority) // Add items maxQueue.push('d', 5); console.log(maxQueue.peek()); // 'd' // Check size console.log(maxQueue.size); // 3 // Clear maxQueue.clear(); console.log(maxQueue.isEmpty()); // true
Debug
Known issues
gotchaBucket priority queue only works with non-negative integer priorities. Using non-integer or negative priorities may cause unexpected behavior.
fix
Ensure all priorities are integers >= 0.
affects: >=0.0.0
gotchaThe queue does not support duplicate items. 'has' and 'contains' methods rely on reference equality, not value equality.
fix
Use object references carefully; consider using unique identifiers.
affects: >=0.0.0
gotchaThe 'refill' method clears the queue before adding new items; any previously stored items are lost.
fix
If you need to preserve old items, use 'push' individually instead.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: MinBucketQueue is not a constructor
Using default import instead of named import.
fix
Use import { MinBucketQueue } from 'bucket-priority-queue'.
Cannot find module 'bucket-priority-queue' or its corresponding type declarations.
Missing or incorrect module installation or tsconfig not resolving node_modules.
fix
Run 'npm install bucket-priority-queue' and ensure 'moduleResolution' is set to 'node' or 'node16' in tsconfig.json.
TS2345: Argument of type 'number' is not assignable to parameter of type 'Priority'.
Priority type is exported as a type, but not needed for usage; TypeScript may infer incorrectly.
fix
The error is misleading; priorities are numbers. If using 'Priority' as a type, import it: import type { Priority } from 'bucket-priority-queue'.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
55 hits · last 30 days
node
48
Perplexity
1
OpenAI (training)
1
Resources
bucket-priority-queue — npm install bucket-priority-queue · libregistry