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

    Interface IPriorityQueue<T, P>

    Interface representing a priority queue data type.

    A priority queue is a collection where each item has a priority associated with it. Items with higher priority are served before items with lower priority.

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

    Type Parameters

    • T = unknown

      The type of elements in the priority queue.

    • P = number

      The type of priority values.

    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.

    Predicate function which determine if one priority is higher than another.

    Methods

    • Returns AsyncIterator<[T, P], any, any>

    • Returns Iterator<Promisable<[T, P]>, any, any>

    • Removes and returns the item with the highest priority from the priority queue.

      Returns Promisable<T | undefined>

      The item with the highest priority, or undefined if the queue is empty.

    • Inserts one or more items with their associated priorities into the priority queue.

      Parameters

      • priority: P

        The priority of the items to insert.

      • ...items: T[]

        The items to insert.

      Returns Promisable<void>

      If the operation would exceed the deque's capacity.

    • Returns the item with the highest priority without removing it from the queue.

      Returns Promisable<T | undefined>

      The item with the highest priority, or undefined if the queue is empty.

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

      Parameters

      • condition: Predicate<[[T, P]]>

        A predicate function to identify the item to replace.

      • newItem: [T, P]

        The new item to insert.

      Returns Promisable<boolean>

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

    • Updates the priority of an existing item in the priority queue.

      Parameters

      • item: T

        The item whose priority is to be updated.

      • newPriority: P

        The new priority of the item.

      Returns Promisable<boolean>

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

      Parameters

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

        Optional abort signal to cancel the operation.

      Returns PromiseLike<void>

      IPriorityQueue.insert