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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sequence-heap

v0.0.9

Published

A non-tree heap implementation using sorted linked lists. Has typescript support.

Downloads

4

Readme

Sequence Heap img img img

The nerd's description

sequence-heap.js orders elements in streaming-fashion just like any heap, allowing it to be used as a priority queue. Implemented as sorted linked lists, the performance is comparable, but not as good as a binary heap implemented over an array. (Don't have hard numbers at this time).

This variant of a sequence heap maintains the heap invariant by splitting linked lists when they hold too many elements. How many? Specify this with rankFactor. This means each linked list progressing in rank holds rankFactor times more elements than the previous linked list. See Comparison.

In the sequence heap paper by Brodal (see Further Exploration), his definition of a (non-soft) sequence heap implies successive lists double in size. Here the rankFactor is 2.

The townsfolk's description

She holds her hands like an altar of death.

A small dot of light blooms from page, first marigold, light canary, then white and hot before a black circle of cinder appears underneath. Atop the book, the chain worm glows red and convulses. It clinks and rattles, jerking hither and yon, desperate to escape her flames. Its crying both enrages her and stokes her desire to see it squeal, to witness the entire gamut of its wailing in every degree of suffering measured in Kelvin.

Hotter and higher, the flames whip and crackle wildly. A tree three yards away receives a stray lashing and erupts. She unknowingly smiles at this divine euphony dueted by the hellish wailing one could imagine signified regret. She is fire in meditation.

At last her focus breaks when the chain worm's head rockets off and it's crying no longer. Looking around, she remembers how she got to this empty field. How, for a moment, her vengeance gave her a peace amidst tragedy.

Seeking more, seeking the demon's provenance, she incants: npm author ls sequence-heap.

The spell produces a luminescent writing in the air. The knowledge numbs her, takes away her balance which she finds only after falling into the ground….

Enough talk

Install

npm install sequence-heap

Usage

CommonJS:

const SequenceHeap = require('sequence-heap')

ESM:

import SequenceHeap from 'sequence-heap'

Initialize:

// each linked list will increase in size by 4 times compared to the previous linked list
const rankFactor = 4 // default is 2
let heap = new SequenceHeap((a,b) => a - b, rankFactor)

// Fill heap
let i = 10
while(i > 0) {
  heap.insert(Math.random() * 100)
  i--
}

// Prints elements in ascending order
while(heap.size > 0) {
  console.log(heap.pop())
}

Worst Case Time Complexity Comparison

| | sequence heap | binary heap | |----------- |------------------- |----------- | | find_min | O(1)** or O(logn) | O(1) | | insert | O(log(n))* | O(log(n)) | | delete_min | O(log(n)) | O(log(n)) |

* amortized

** reducing peek to O(1) can be done by keeping track of the min from insertions and deletions Watch my video proving time complexity for these operations.

Further exploration

Wikipedia as of 2024-06-13 still has no article on sequence heaps. Prior articles do not necessarily agree on nomenclature either.

Contributing

I would like a house. Please and thank you. Or help editing my writing.

This project lives primarily at sequence-heap.js where issues are best filed. You may sign in or create an account directly, or use one of several OAuth 2.0 providers.

Running Tests

npm run test
# or
npx mocha ./test/*.js