@subsquid/util-internal-binary-heap
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@subsquid/util-internal-binary-heap

Classical implementation of binary heap data structure.

Usage

import {Heap} from "@subsquid/util-internal-binary-heap"

const h = new Heap(function compare(a, b) {
  return a - b
})

h.push(5)
h.push(0)
h.push(10)

h.pop() // => 0
h.pop() // => 5
h.pop() // => 10

h.init([5, 2, 3, 1, 4]) // will modify array in-place and use it as a storage
h.pop() // => 1

h.peek() // => 2
h.size() // => 4

h.resort() // When you have mutable objects,
           // call this to restore heap property after changes

Readme

Keywords

none

Package Sidebar

Install

npm i @subsquid/util-internal-binary-heap

Weekly Downloads

2,502

Version

1.0.0

License

GPL-3.0-or-later

Unpacked Size

4.21 kB

Total Files

7

Last publish

Collaborators

  • subsquid