binaryheap
A simple binary heap
Last updated 14 years ago by tjfontaine .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install binaryheap 
SYNC missed versions from official npm registry.

BinaryHeap

Basic binary heap tree using linked lists

Usage

var BinaryHeap = require('binaryheap');
var heap = new BinaryHeap();

var a = [6, 5, 3, 1, 8, 7, 2, 4];

a.forEach(function (k) {
  heap.insert({ value: k }, k);
});

heap.print();

while (heap.length) {
  console.log('popping', heap.pop().value);
}

By default it stores as a max-heap, if you pass truthy to the constructor though it will behave as a min-heap.

Methods

  • insert(obj, key) -- obj can be any new or existing object, and key is any value that behaves sanely with > or <
  • pop() -- removes and returns the maximum or minimum object from the root of the heap
  • remove(obj) -- removes a previously inserted object from the heap
  • print() -- mostly for debugging purposes prints a graphviz dot style digraph to confirm ordering

Members

  • length -- number of objects currently in the heap

Current Tags

  • 0.0.3                                ...           latest (14 years ago)

3 Versions

  • 0.0.3                                ...           14 years ago
  • 0.0.2                                ...           14 years ago
  • 0.0.1                                ...           14 years ago
Maintainers (1)
Downloads
Total 11
Today 0
This Week 2
This Month 7
Last Day 1
Last Week 5
Last Month 2
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE