UNPKG

@thi.ng/heaps

Version:

Various heap implementations for arbitrary values and with customizable ordering

44 lines 1.63 kB
import type { ICopy, IEmpty, IStack } from "@thi.ng/api"; import type { DHeapOpts } from "./api.js"; import { Heap } from "./heap.js"; export declare const defDHeap: <T>(values?: Iterable<T> | null, opts?: Partial<DHeapOpts<T>>) => DHeap<T>; /** * Generic d-ary heap / priority queue with configurable arity (default = 4) and * ordering via user-supplied comparator. * * @remarks * By default, implements min-heap ordering and uses * [`compare`](https://docs.thi.ng/umbrella/compare/functions/compare.html). The * arity `d` must be >= 2 (default: 4). If `d=2`, the default binary * {@link Heap} implementation will be faster. * * Reference: * https://en.wikipedia.org/wiki/D-ary_heap */ export declare class DHeap<T> extends Heap<T> implements ICopy<DHeap<T>>, IEmpty<DHeap<T>>, IStack<T, T, DHeap<T>> { /** * Returns index of parent node or -1 if `idx < 1`. * * @param idx - index * @param d - branch factor */ static parentIndex(idx: number, d?: number): number; /** * Returns index of 1st child or -1 if `idx < 0`. * * @param idx - index * @param d - branch factor */ static childIndex(idx: number, d?: number): number; protected d: number; constructor(values?: Iterable<T> | null, opts?: Partial<DHeapOpts<T>>); copy(): DHeap<T>; empty(): DHeap<T>; parent(n: number): T | undefined; children(n: number): T[] | undefined; leaves(): T[]; heapify(vals?: T[]): void; protected percolateUp(i: number, vals?: T[]): void; protected percolateDown(i: number, vals?: T[]): void; } //# sourceMappingURL=dheap.d.ts.map