Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UniquePriorityQueue<T>

Extension of PriorityQueue. Enforces uniqueness of enqueued elements; attempts made to enqueue an element that is already in the queue will be ignored.

Elements must implement getKey() method

Type parameters

Hierarchy

Index

Constructors

constructor

Accessors

invertPriority

  • get invertPriority(): boolean
  • set invertPriority(val: boolean): void
  • Get/Set whether this queue has inverted priority or not. False: smallest values will be at the front of the queue. True: largest values will be at the front of the queue. False by default. Setting the value will cause the queue to be reordered.

    property

    {boolean}

    Returns boolean

  • Get/Set whether this queue has inverted priority or not. False: smallest values will be at the front of the queue. True: largest values will be at the front of the queue. False by default. Setting the value will cause the queue to be reordered.

    property

    {boolean}

    Parameters

    • val: boolean

    Returns void

length

  • get length(): number
  • Returns the size of the queue

    Returns number

    The size of the queue.

Methods

clear

  • clear(): void

contains

  • contains(element: T): boolean
  • Returns whether the item exists in the queue.

    Parameters

    • element: T

      The element to search for.

    Returns boolean

    True if the element is in the queue; false otherwise.

extractMax

  • extractMax(): any

filter

  • filter(queryCallback: (el: T) => boolean): T[]
  • Retrieve elements that match a query.

    Parameters

    • queryCallback: (el: T) => boolean

      A callback that returns whether an element matches

        • (el: T): boolean
        • Parameters

          • el: T

          Returns boolean

    Returns T[]

    The element if found; null otherwise.

getByIndex

  • getByIndex(i: number): T
  • Retrieve the element at a specified index. Throws an error if i is out of bounds.

    Parameters

    • i: number

      The index of the target element

    Returns T

    The element found at the specified index.

indexOf

  • indexOf(element: T): number
  • Returns the index of the item if it exists in the queue.

    Parameters

    • element: T

      The element to search for.

    Returns number

    The index of the element in the queue; -1 if it does not exist.

insert

  • insert(element: T): void

peek

  • peek(): T

poll

  • poll(): any

pop

  • pop(): any

push

  • push(value: T): void

remove

  • remove(element: T): void

setInvertPriority

  • setInvertPriority(bool: boolean): void
  • Set whether this queue has inverted priority or not. False: smallest values will be at the front of the queue. True: largest values will be at the front of the queue. False by default. Setting the value will cause the queue to be reordered.

    Parameters

    • bool: boolean

      The value to set

    Returns void

size

  • size(): number

toSortedArray

  • toSortedArray(): T[]

updateElement

  • updateElement(element: T): void
  • Used to update the queue when a element's priority has been changed. Assumes the element has already been inserted. Assumes you have updated the value on your own.

    Parameters

    • element: T

      The element to update

    Returns void

Generated using TypeDoc