@ac-essentials/misc-util
    Preparing search index...

    Interface IHeap<T>

    Interface representing a heap data type.

    interface IHeap<T = unknown> {
        capacity: number;
        "[asyncIterator]"(): AsyncIterator<T, any, any>;
        "[iterator]"(): Iterator<Promisable<T>, any, any>;
        clear(): Promisable<void>;
        concat(...items: T[]): MaybeAsyncIterableIterator<T>;
        count(): Promisable<number>;
        extract(): Promisable<T | undefined>;
        extractAndInsert(item: T): Promisable<T | undefined>;
        insert(...items: T[]): Promisable<void>;
        insertAndExtract(item: T): Promisable<T | undefined>;
        remove(
            condition: Predicate<[T]>,
        ): Promisable<MaybeAsyncIterableIterator<T>>;
        removeFirst(condition: Predicate<[T]>): Promisable<boolean>;
        replace(
            condition: Predicate<[T]>,
            newItemFactory: Callable<[T], T>,
        ): Promisable<MaybeAsyncIterableIterator<T>>;
        replaceFirst(condition: Predicate<[T]>, newItem: T): Promisable<boolean>;
        root(): Promisable<T | undefined>;
        waitInsert(
            items: Iterable<T>,
            signal?: AbortSignal | null,
        ): PromiseLike<void>;
    }

    Type Parameters

    • T = unknown

      The type of elements in the heap.

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    capacity: number

    The maximum number of elements the collection can hold. If the collection is unbounded, this will be Infinity.

    Methods

    • Returns AsyncIterator<T, any, any>

    • Returns Iterator<Promisable<T>, any, any>

    • Removes and returns the root item of the heap.

      Returns Promisable<T | undefined>

      The root item of the heap, or undefined if the heap is empty.

    • Extracts the root item from the heap and inserts a new item in one operation.

      Parameters

      • item: T

        The item to replace.

      Returns Promisable<T | undefined>

    • Inserts one or more items into the heap.

      Parameters

      • ...items: T[]

        The items to insert.

      Returns Promisable<void>

      If the operation would exceed the heap capacity.

    • Inserts an item into the heap and then extracts and returns the root item in one operation.

      Parameters

      • item: T

        The item to insert and extract.

      Returns Promisable<T | undefined>

    • Replaces the first occurence of the item matching the given predicate in the collection with a new item.

      Parameters

      • condition: Predicate<[T]>

        A predicate function to identify the item to replace.

      • newItem: T

        The new item to insert.

      Returns Promisable<boolean>

      true if the item was found and replaced, false otherwise.

    • Returns the root item of the heap without removing it.

      Returns Promisable<T | undefined>

      The root item of the heap, or undefined if the heap is empty.

    • Same as insert, but waits for capacity if the operation would exceed it.

      Parameters

      • items: Iterable<T>
      • Optionalsignal: AbortSignal | null

        Optional abort signal to cancel the operation.

      Returns PromiseLike<void>

      IHeap.insert