Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HeapPriorityQueue<T>

HeapPriorityQueue allows for push/pop based on an attribute of the inserted objects. The heap based implementation underneath has theoretic O(log(n)) insert/pop time and O(c) peek time.

Because the bubble up/down might not preserve order within items of the same priority, the array-priority-queue can be a better though slower choice in some cases.

Type parameters

  • T

Hierarchy

  • HeapPriorityQueue

Index

Constructors

Methods

Constructors

constructor

  • Parameters

    • priorityFunc: (t: T) => number

      A function that takes the a value that has previously been inserted, and returns a priority.

      A lower score is higher priority.

      Ex. (monster) => monster.speed

        • (t: T): number
        • Parameters

          • t: T

          Returns number

    Returns HeapPriorityQueue

Methods

insert

  • insert(data: T): void

peek

  • peek(): T

pop

  • pop(): undefined | T
  • Get the item with the lowest priority score, removing it from the queue.

    Returns undefined | T

    • The lowest priority item

size

  • size(): number

Generated using TypeDoc