API Docs for: 0.1.21
Show:

PriorityQueue Class

The PriorityQueue class provides the main functionality of an prioritized queue, implemented using a max heap.

Methods

_child

(
  • n
)
private

Get index of left child element in binary tree stored in array

Parameters:

  • n Object

Returns:

number

_displayNode

(
  • node
  • prefix
  • last
)
private

Visually display heap tree

Parameters:

  • node Object
  • prefix Object
  • last Object

Returns:

String

_parent

(
  • n
)
private

Get index of parent element in binary tree stored in array

Parameters:

  • n Object

Returns:

number

_siftDown

(
  • i
)
private

Sift down elements in binary tree

Parameters:

  • i Object

_siftUp

(
  • i
)
private

Sift elements in binary tree

Parameters:

  • i Object

_swap

(
  • first
  • second
)
private

Swap 2 elements in binary tree

Parameters:

  • first Object
  • second Object

compare

(
  • first
  • second
)

Inherited from Heap but overwritten in Datastructures/PriorityQueue.ts:46

Compare elements in order to place them correctly in the heap while sifting up.

Parameters:

  • first Object

    The value of the first node being compared.

  • second Object

    The value of the second node being compared.

Returns:

number Result of the comparison, positive integer if first is greater than second, 0 if they are equal, negative integer otherwise. Having multiple elements with the same value in a Heap is not recommended. They will end up in an arbitrary relative position.

count

()

Counts the number of elements in the heap

Returns:

number the number of elements in the heap.

current

()

Return current node pointed by the iterator

Returns:

any The current node value.

dequeue

()

Dequeues a node from the queue

Returns:

any The value of the dequeued node.

enqueue

(
  • value
  • priority
)

Adds an element to the queue

Parameters:

  • value Object

    The value to enqueue.

  • priority Object

    The priority of value.

Returns:

void

extract

()

Extracts a node from top of the heap and sift up

Returns:

any The value of the extracted node.

insert

(
  • value
)

Inserts an element in the heap by sifting it up

Parameters:

  • value Object

    The value to insert.

Returns:

void

isEmpty

()

Checks whether the heap is empty

Returns:

boolean whether the heap is empty.

key

()

Return current node index

Returns:

any The current node index.

next

()

Move to the next node

Returns:

void

prev

()

Move to previous entry

Returns:

void

rewind

()

Rewind iterator back to the start (no-op)

Returns:

void

toArray

()

Serializes the heap to array

Returns:

Array The serialized array.

top

()

Inherited from Heap but overwritten in Datastructures/PriorityQueue.ts:36

Peeks at the node from the top of the heap

Returns:

any The value of the node on the top.

toString

()

Serializes the heap to string

Returns:

string The serialized string.

valid

()

Check whether the heap contains more nodes

Returns:

boolean true if the heap contains any more nodes, false otherwise.

Properties

_key

Number private

Iteration pointer

_tree

Array private

Binary tree storage array

_type

Number private

Heap type