Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

binaryheap

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binaryheap

A simple binary heap

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
increased by2.87%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 24 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc