Skip to main content

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score58%
Published2 years ago (0.215.0)

Classes

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

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

  • clear(): void

    Removes all values from the binary heap.

  • drain(): IterableIterator<T>

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

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

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

  • isEmpty(): boolean

    Checks if the binary heap is empty.

  • length(): number

    The amount of values stored in the binary heap.

  • 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.

  • toArray(): T[]

    Returns the underlying cloned array in arbitrary order without sorting

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/data-structures

Import symbol

import * as mod from "@std/data-structures/binary_heap";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/data-structures/binary_heap";