npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@himenon/priority-queue

v0.1.1

Published

Priority Queue

Readme

@himenon/priority-queue

A lightweight, high-performance priority queue implementation in TypeScript with flexible ordering (min-heap / max-heap) and built-in iterator support.
Designed for performance-critical applications and predictable memory usage, with behavior inspired by standard binary heap algorithms.

✨ Features

  • Min-heap / Max-heap switching at runtime (setMinHeap, setMaxHeap)
  • Custom priorities (number) per element
  • Stable performance via binary heap (O(log n) enqueue/dequeue)
  • Iterable: use in for...of, spread, etc.
  • Bulk removal with drain() or sorted drainFast()
  • Memory-efficient: optimized for minimal overhead
  • ✅ Fully written in modern TypeScript, no dependencies

📦 Installation

pnpm i @himenon/priority-queue

🔧 Usage

import { PriorityQueue } from "@himenon/priority-queue";

const pq = new PriorityQueue<string>(); // Default: min-heap

pq.enqueue("task: low", 5);
pq.enqueue("task: high", 1);

console.log(pq.dequeue()); // => "task: high"

pq.setMaxHeap(); // switch dynamically
pq.enqueue("urgent", 10);
pq.enqueue("background", 1);

console.log([...pq]); // iterable

📈 Benchmark Results

The following charts compare this PriorityQueue implementation with yocto-queue, using statistical aggregates over 10 trials. Error bars represent the 25th to 75th percentile range.



📌 Notes

  • Benchmarks were executed 10 times per heap size.
  • All plots include mean values with p25–p75 error bars.
  • Visualizations were generated via matplotlib in Docker.
  • Raw CSV data and scripts can be found under benchmark/.

⏱️ Performance Considerations: PriorityQueue vs yocto-queue

This implementation of PriorityQueue adopts a binary heap internally in order to support prioritized ordering. While this introduces higher time complexity compared to plain FIFO queues like yocto-queue, it is a conscious trade-off that ensures ordering guarantees while maintaining low memory footprint.

📊 Comparison Table

| Operation | yocto-queue | PriorityQueue (this) | Complexity Increase | Reason | | ------------ | ----------------- | ---------------------- | ------------------- | ------------------------------------------ | | enqueue | O(1) | O(log n) | Yes 🔺 | Maintains heap order via bubbleUp | | dequeue | O(1) | O(log n) | Yes 🔺 | Requires heap reordering via bubbleDown | | peek | O(1) | O(1) | No ✅ | Both read front/root value | | drain | O(n) | O(n log n) | Yes 🔺 | Sequential dequeue() or heap sort | | Memory usage | Low (linked list) | Lower (flat array) | No ✅ | Binary heap stored as flat array (compact) |

🧠 Why the Priority Queue is Slower

Unlike yocto-queue, which is designed solely for FIFO operations and does not preserve any ordering beyond insertion time, PriorityQueue must always ensure that the highest or lowest priority item can be dequeued efficiently. This requires maintaining a partially ordered tree (heap), where insertion and removal involve comparisons and restructuring.

Thus, the increase in time complexity from O(1) to O(log n) is the necessary cost of enabling

LICENCE

@Himenon/priority-queue・MIT