New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

tiny-heap

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-heap

A tiny little heap implementation.

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
5
150%
Maintainers
1
Weekly downloads
 
Created
Source

A tiny little heap implementation.

Example

const tinyHeap = require("tinyHeap")

const minHeap = tinyHeap()
minHeap.push(3)
minHeap.push(2)
minHeap.push(1)
const top = minHeap.pop()
// 1

API

heap(inOrder=min)

Initializes a new tiny heap.

The inOrder argument is a function used to compare parent nodes of the heap to keep it in order. The default value makes it a min-heap, like this:

const min = (parent, child) => {
  return parent < child
}

min and max implementations are provided on tinyHeap:

const maxHeap = tinyHeap(tinyHeap.max)
maxHeap.push(1)
maxHeap.push(2)
maxHeap.push(3)
const top = maxHeap.pop()
// 3

push(value)

Pushes a value onto the heap. It will be sifted into position using the inOrder function.

pop()

Pops the top value of the heap. For a min-heap this will be the min value. For a max-heap it'll be the max value.

peek()

Gets the top value of the heap without popping it. Useful if you need to compare before you pop.

size()

Gets the number of nodes in the heap.

all()

Returns all of the nodes of the heap as an array. Nodes are ordered top to bottom, left to right.

FAQs

Package last updated on 18 Nov 2017

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