Class PriorityQueue<T>

Type Parameters

  • T

Hierarchy

Accessors

  • get length(): number
  • Returns

    The size of the container.

    Example

    const container = new Vector([1, 2]);
    console.log(container.length); // 2

    Returns number

Methods

  • Description

    Push element into a container in order.

    Returns

    The size of heap after pushing.

    Example

    queue.push(1);
    

    Parameters

    • item: T

      The element you want to push.

    Returns void

  • Description

    Check if element is in heap.

    Returns

    Whether element is in heap.

    Example

    const que = new PriorityQueue([], (x, y) => x.id - y.id);
    const obj = { id: 1 };
    que.push(obj);
    console.log(que.find(obj)); // true

    Parameters

    • item: T

      The item want to find.

    Returns boolean

  • Description

    Remove specified item from heap.

    Returns

    Whether remove success.

    Example

    const que = new PriorityQueue([], (x, y) => x.id - y.id);
    const obj = { id: 1 };
    que.push(obj);
    que.remove(obj);

    Parameters

    • item: T

      The item want to remove.

    Returns boolean

  • Description

    Update item and it's pos in the heap.

    Returns

    Whether update success.

    Example

    const que = new PriorityQueue([], (x, y) => x.id - y.id);
    const obj = { id: 1 };
    que.push(obj);
    obj.id = 2;
    que.updateItem(obj);

    Parameters

    • item: T

      The item want to update.

    Returns boolean

Constructors

  • Description

    PriorityQueue's constructor.

    Example

    new PriorityQueue();
    new PriorityQueue([1, 2, 3]);
    new PriorityQueue([1, 2, 3], (x, y) => x - y);
    new PriorityQueue([1, 2, 3], (x, y) => x - y, false);

    Type Parameters

    • T

    Parameters

    • container: initContainer<T> = []

      Initialize container, must have a forEach function.

    • cmp: ((x: T, y: T) => number) = ...

      Compare function.

        • (x: T, y: T): number
        • Parameters

          • x: T
          • y: T

          Returns number

    • copy: boolean = true

      When the container is an array, you can choose to directly operate on the original object of the array or perform a shallow copy. The default is shallow copy.

    Returns PriorityQueue<T>

Generated using TypeDoc