tinyqueue is a lightweight, efficient JavaScript library providing a binary heap-based priority queue data structure. Currently at version 3.0.0, it offers fundamental operations like `push`, `pop`, and `peek` with minimal overhead. The library's core design prioritizes simplicity and a small bundle size, distinguishing it from more feature-rich or specialized queue implementations. It supports custom comparison functions, allowing users to define priority based on object properties rather than just raw values. While release cadence is not strictly regular, it sees updates for performance improvements and compatibility, with the most recent major update (v3.0.0) shifting to an ES module-only distribution.
npm install tinyqueueVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize a TinyQueue, add elements, retrieve the highest priority item, inspect the queue's length, and use custom comparators for complex objects, including how to turn a queue into a sorted array.
Migrate your project to use ES module imports (e.g., `import TinyQueue from 'tinyqueue';`). Ensure your Node.js environment or build tool supports ES modules. For browser usage without a build step, load via a CDN that provides ESM compatibility or bundle it with a tool like Rollup/Webpack.
Evaluate `flatqueue` if `tinyqueue`'s general-purpose binary heap performance does not meet specific, high-frequency numerical processing requirements.
If you need to preserve the original array, pass a shallow copy to the constructor: `new TinyQueue([...myArray], comparator)`.
Change the import statement to `import TinyQueue from 'tinyqueue';`. Ensure your project's `package.json` correctly specifies `"type": "module"` if you are using Node.js ES modules, or adjust your build system accordingly.
For browser usage without a build system, use a modern CDN that provides ES module builds (e.g., `https://cdn.jsdelivr.net/npm/tinyqueue@3/tinyqueue.mjs`). If using a build system, import `tinyqueue` as an ES module and let your bundler handle it.
No dependency data recorded yet.