std/collections/binary_heap.ts

Deno standard library
Go to Latest
class BinaryHeap
implements Iterable<T>
import { BinaryHeap } from "https://deno.land/std@0.147.0/collections/binary_heap.ts?s=BinaryHeap";

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)
[src]

Properties

readonly
length: number
[src]

The amount of values stored in the binary heap.

Methods

clear(): void[src]

Removes all values from the binary heap.

drain(): IterableIterator<T>[src]

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

isEmpty(): boolean[src]

Checks if the binary heap is empty.

peek(): T | undefined[src]

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

pop(): T | undefined[src]

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

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

Adds values to the binary heap.

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

Static Methods

from<T>(collection: ArrayLike<T> | Iterable<T> | BinaryHeap<T>): BinaryHeap<T>[src]

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

from<T>(collection: ArrayLike<T> | Iterable<T> | BinaryHeap<T>, options: { compare?: (a: T, b: T) => number; }): BinaryHeap<T>[src]
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>[src]
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>[src]