Skip to main content
Module

x/collections/mod.ts>BinaryHeap

Collection data structures that are not standard built-in objects in JavaScript. This includes a vector (double-ended queue), binary heap (priority queue), binary search tree, and a red black tree.
Very Popular
Latest
class BinaryHeap
implements Iterable<T>
Deprecated
import { BinaryHeap } from "https://deno.land/x/collections@0.12.1/mod.ts";

A priority queue implemented with a binary heap. The heap is in decending order by default, using JavaScript's built in comparison operators to sort the values.

Constructors

new
BinaryHeap(compare?: (a: T, b: T) => number)

Properties

private
data: T[]
readonly
length: number

The amount of values stored in the binary heap.

Methods

clear(): void

Removes all values from the binary heap.

drain(): IterableIterator<T>

Returns an iterator for retrieving and removing values from the binary heap.

isEmpty(): boolean

Checks if the binary heap is empty.

peek(): T | undefined

Returns the greatest value in the binary heap, or undefined if it is empty.

pop(): T | undefined

Removes the greatest value from the binary heap and returns it, or null if it is empty.

push(...values: T[]): number

Adds values to the binary heap.

[Symbol.iterator](): IterableIterator<T>

Static Methods

from<T, U>(collection: ArrayLike<T> | Iterable<T> | BinaryHeap<T>): BinaryHeap<U>

Creates a new binary heap from an array like or iterable object.

from<T, U>(collection: ArrayLike<T> | Iterable<T> | BinaryHeap<T>, options: { compare?: (a: U, b: U) => number; }): BinaryHeap<U>
from<T, U, V>(collection: ArrayLike<T> | Iterable<T> | BinaryHeap<T>, options: { compare?: (a: U, b: U) => number; map: (value: T, index: number) => U; thisArg?: V; }): BinaryHeap<U>