/** @import { Comparator } from "./index.js" */ /** * @template T * @class * @category Data Structures */ export class Heap { /** * Creates a Heap from an Array * * @template T * @param {T[]} elements - Contains the elements for the Heap. * @param {(d: T) => number} accessor - Function returns the value of the element. * @param {"min" | "max" | Comparator} [comparator="min"] - Function returning true or false * defining the wished order of the Heap, or String for predefined function. ("min" for a Min-Heap, "max" for a * Max_heap). Default is `"min"` * @returns {Heap} */ static heapify( elements: T_1[], accessor: (d: T_1) => number, comparator?: "min" | "max" | Comparator, ): Heap; /** * A heap is a datastructure holding its elements in a specific way, so that the top element would be the first * entry of an ordered list. * * @param {T[]?} elements - Contains the elements for the Heap. `elements` can be null. * @param {(d: T) => number} accessor - Function returns the value of the element. * @param {"min" | "max" | Comparator} [comparator="min"] - Function returning true or false * defining the wished order of the Heap, or String for predefined function. ("min" for a Min-Heap, "max" for a * Max_heap). Default is `"min"` * @see {@link https://en.wikipedia.org/wiki/Binary_heap} */ constructor( elements: (T[] | null) | undefined, accessor: (d: T) => number, comparator?: "min" | "max" | Comparator, ); /** @type {{ element: T; value: number }[]} */ _container: { element: T; value: number; }[]; /** @type {Comparator} */ _comparator: Comparator; /** @type {(d: T) => number} */ _accessor: (d: T) => number; /** * Swaps elements of container array. * * @private * @param {number} index_a * @param {number} index_b */ private _swap; /** @private */ private _heapify_up; /** * Pushes the element to the heap. * * @param {T} element * @returns {Heap} */ push(element: T): Heap; /** * @private * @param {Number} [start_index=0] Default is `0` */ private _heapify_down; /** * Removes and returns the top entry of the heap. * * @returns {{ element: T; value: number } | null} Object consists of the element and its value (computed by * `accessor`}). */ pop(): { element: T; value: number; } | null; /** * Returns the top entry of the heap without removing it. * * @returns {{ element: T; value: number } | null} Object consists of the element and its value (computed by * `accessor`). */ get first(): { element: T; value: number; } | null; /** * Yields the raw data * * @yields {T} Object consists of the element and its value (computed by `accessor`}). */ iterate(): Generator; /** * Returns the heap as ordered array. * * @returns {T[]} Array consisting the elements ordered by `comparator`. */ toArray(): T[]; /** * Returns elements of container array. * * @returns {T[]} Array consisting the elements. */ data(): T[]; /** * Returns the container array. * * @returns {{ element: T; value: number }[]} The container array. */ raw_data(): { element: T; value: number; }[]; /** * The size of the heap. * * @returns {number} */ get length(): number; /** * Returns false if the the heap has entries, true if the heap has no entries. * * @returns {boolean} */ get empty(): boolean; } import type { Comparator } from "./index.js"; //# sourceMappingURL=Heap.d.ts.map