Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PriorityQueue

Priority Queue data structure

Hierarchy

  • MinHeap
    • PriorityQueue

Constructors

constructor

  • Returns PriorityQueue

Properties

compare

compare: Comparator

heapContainer

heapContainer: any[]

priorities

priorities: Map<any, any>

Methods

add

  • Parameters

    • item: any
    • priority: number = 0

    Returns PriorityQueue

changePriority

  • Parameters

    • item: any
    • priority: number

    Returns PriorityQueue

comparePriority

  • comparePriority(a: any, b: any): 0 | "1" | "-1"
  • Parameters

    • a: any

      Item A

    • b: any

      Item B

    Returns 0 | "1" | "-1"

compareValues

  • compareValues(a: string | number, b: string | number): 0 | "1" | "-1"
  • Parameters

    • a: string | number
    • b: string | number

    Returns 0 | "1" | "-1"

find

  • find(item: any, comparator?: Comparator): number[]
  • Parameters

    • item: any

      item to find

    • comparator: Comparator = ...

      A comparator instance

    Returns number[]

    array of indices of the item in the heap

findByValue

  • findByValue(item: any): number[]
  • Parameters

    • item: any

    Returns number[]

getLeftChildIndex

  • getLeftChildIndex(parentIndex: number): number
  • Parameters

    • parentIndex: number

      Parent's index

    Returns number

    Index of the left child

getParentIndex

  • getParentIndex(childIndex: number): number
  • Parameters

    • childIndex: number

      Index of the node

    Returns number

    Parent's index

getRightChildIndex

  • getRightChildIndex(parentIndex: number): number
  • Parameters

    • parentIndex: number

      Parent's index

    Returns number

    Index of the right child

hasLeftChild

  • hasLeftChild(parentIndex: number): boolean
  • Parameters

    • parentIndex: number

    Returns boolean

hasParent

  • hasParent(childIndex: number): boolean
  • Parameters

    • childIndex: number

      Index of the node

    Returns boolean

hasRightChild

  • hasRightChild(parentIndex: number): boolean
  • Parameters

    • parentIndex: number

      Parent's index

    Returns boolean

hasValue

  • hasValue(item: any): boolean
  • Parameters

    • item: any

    Returns boolean

heapifyDown

  • heapifyDown(startIndex?: number): void
  • Compare the parent with both of it's children and swap it with the appropriate child (smaller child for MinHeap and bigger child for MaxHeap). Do the same for next children after swap.

    Parameters

    • Optional startIndex: number

      Index to start heapify process from

    Returns void

heapifyUp

  • heapifyUp(startIndex?: number): void
  • Take the last item (last in the container array or bottom left in the heap) and lift it up until its in the correct position with respect to its parent

    Parameters

    • Optional startIndex: number

      Index to start heapify process from

    Returns void

isEmpty

  • isEmpty(): boolean
  • Returns boolean

isPairInCorrectOrder

  • isPairInCorrectOrder(parent: any, child: any): boolean
  • Parent must be less than or equal to the child node

    Parameters

    • parent: any

      Parent Node

    • child: any

      Child Node

    Returns boolean

leftChild

  • leftChild(parentIndex: number): any
  • Parameters

    • parentIndex: number

      Parent's index

    Returns any

parent

  • parent(childIndex: number): any
  • Parameters

    • childIndex: number

      Index of the node

    Returns any

peak

  • peak(): any
  • Get the root node without modifying the heap

    Returns any

poll

  • poll(): any
  • Remove the root node

    Returns any

remove

  • Parameters

    Returns PriorityQueue

rightChild

  • rightChild(parentIndex: number): any
  • Parameters

    • parentIndex: number

      Parent's index

    Returns any

swap

  • swap(index1: number, index2: number): void
  • Parameters

    • index1: number

      Index of the first item

    • index2: number

      Index of the second item

    Returns void

toString

  • toString(): string
  • Returns string