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

binary_heap

v0.9.5

Published

A binary heap implementation using an array.

Readme

A binary heap implementation using an array to store data.

The binary heap is an efficient data structure that keeps the highest/lowest element at the top. push and pop have a time complexity of O(n*log(n)).

By default, BinaryHeap will maintain the lowest number at the "top" by default. Provide an alternate predicate/compare function to sort in different order or according to different criteria.

compareFunc should return true or false, according to how you wish the elements to be ordered, by default true is returned if x is smaller than y according to less than operator.

Functions:

  • .push(elt): insert single element into BinaryHeap. Asymptotic complexity O(log(n)) where n is current size of data on the heap

  • .pop(): retrieve single element from the top of the BinaryHeap. Asymptotic complexity O(log(n)) where n is current size of data on the heap

  • .pushArray(arr): inserts array arr one element at a time into BinaryHeap using the .push() function. Asymptotic complexity O(n * log(m)) where n is size of _data and m is the size of array passed as argument to function.

  • .popArray(n): retrieves n elements from the heap in order and returns them as an array. The argument n should be an integer, if it's left blank you're essentially performing heapsort as the entire heap gets returned in sorted order as an array. Asymptotic complexity O(n * log(m)) where n is the number of elements you're retrieving and m is the size of the heap

  • .peek(): returns a deep copy of the top element of the heap. The returned element can safely be modified without affecting the stability of the binary heap. Asymptotic complexity O(1).

  • .peek_unsafe(): same as peek() but does not deep-copy. Use when deep-copy doesn't work or recursion for cloning would be too deep but ensure you don't modify returned objects.

  • .peekArray(n): returns an array of n deep-copied elements from the heap. The function does not affect the heap, nor does modifying the elements of the returned array. Asymptotic complexity O(n * log(n)) where n is the number of elements being retrieved.

  • .peekArray_unsafe(n): same as peekArray(n) but does not deep-copy. Use when deep-copy doesn't work or recursion for cloning would be too deep but ensure you don't modify returned objects.

  • .size(): returns the number of elements on the heap. Constant time.

  • .empty(): returns true when the heap is empty. Constant time.

  • functions starting with _ and _data should not be accessed. They're there for internal book-keeping, storing data, swaps etc.