Registry / devops / heapify

heapify

JSON →
library1.0.2jsnpmunverified

A very fast JavaScript priority queue implemented with a binary heap using parallel typed arrays. Version 1.0.2 is stable with no dependencies, released by luciopaiva. Benchmarks show it outperforms competitors like TinyQueue, FastPQ, FlatQueue, and Closure Library in push, pop, and interleaved operations. Supports min-heap, custom capacity, and various key/priority types. Ships TypeScript types and is available for Node.js (ESM and CJS) and browsers (global script or ESM). Suitable for performance-critical applications requiring low-latency queue operations.

npm install heapify
INSTALL
IMPORT
SIG · HEAPIFY
H
heapify
devopsjavascriptv1.0.2
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.

MinQueue
import { MinQueue } from 'heapify'
const MinQueue = require('heapify')
Named export only. For CommonJS, use require('heapify').MinQueue.
MinQueue (CommonJS)
const { MinQueue } = require('heapify')
const MinQueue = require('heapify')
CommonJS destructured require works. Direct assignment returns an object, not the class.
MinQueue (browser global)
const { MinQueue } = Heapify;
const queue = new Heapify.MinQueue();
When loaded via script tag, the library sets window.Heapify object. Access MinQueue via destructuring.
MinQueue (ESM browser)
import { MinQueue } from 'https://unpkg.com/heapify/heapify.mjs'
import MinQueue from 'heapify'
Default import is not available; use named import with the .mjs bundle for native ESM in browsers.

Demonstrates core operations: create MinQueue, push with priority, pop min, peek, peekPriority, clear, and empty queue behavior.

import { MinQueue } from 'heapify'; // Create a min-queue with default capacity (64) const queue = new MinQueue(); // Push elements with priorities queue.push('task1', 10); queue.push('task2', 5); queue.push('task3', 20); // Pop the element with the smallest priority const next = queue.pop(); // 'task2' // Peek at the next element without removing const top = queue.peek(); // 'task1' // Peek at the priority of the next element const topPriority = queue.peekPriority(); // 10 // Check size and capacity console.log(queue.size); // 2 console.log(queue.capacity); // 64 // Clear all elements queue.clear(); console.log(queue.size); // 0 // Pop from empty queue returns undefined console.log(queue.pop()); // undefined
Debug
Known issues
gotchapop() followed quickly by peek() or peekPriority() is O(log n), not O(1).
fix
Avoid mixing pop() and peek() without a push() in between if O(1) peeking is critical.
affects: *
gotchaDefault capacity is 64; pushing more than capacity triggers an internal resize which is O(n).
fix
Specify expected capacity in constructor: new MinQueue(initialCapacity).
affects: *
deprecatedThe library does not support max-queue by default; only min-queue is exported.
fix
For max-queue, use a negative priority or implement a wrapper.
affects: *
gotchaKeys and priorities must be numbers or strings that can be stored in TypedArrays; floating-point priorities may cause precision issues.
fix
Use integer priorities and ensure keys are compatible with Uint32Array or Float64Array.
affects: *
gotchaWhen using the CommonJS require(), the exported object has a MinQueue property, not the class directly.
fix
Use const { MinQueue } = require('heapify'); instead of const MinQueue = require('heapify');
affects: *
Errors
Common errors & fixes
TypeError: heapify_1.MinQueue is not a constructor
Using default import or incorrect destructuring when importing heapify in CommonJS.
fix
Use const { MinQueue } = require('heapify'); for CommonJS.
Cannot find module 'heapify' or its corresponding type declarations.
Missing @types/heapify or the package's types are not recognized by TypeScript.
fix
Ensure you have installed heapify (npm install heapify) and that tsconfig.json includes node_modules types.
Uncaught TypeError: queue.push is not a function
The object returned from heapify is not an instance of MinQueue; likely using wrong import/require pattern.
fix
Use import { MinQueue } from 'heapify' (ESM) or const { MinQueue } = require('heapify') (CJS).
RangeError: Invalid typed array length
Creating a MinQueue with a very large capacity leading to out-of-memory or invalid length.
fix
Reduce initial capacity or increase available memory. Capacity must be a positive integer.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
heapify — npm install heapify · libregistry