1.0.0 • Published 1 year ago

@subsquid/util-internal-binary-heap v1.0.0

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
1 year ago

@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