GeezerVison is showing prishedko.github.io — PriorityQueue | algorithms-ts
This implementation uses a binary heap. The enqueue and dequeue operations take logarithmic
amortized time. The peek, size, and is-empty operations take constant time. Construction
takes time proportional to the specified capacity or the number of items used to initialize the data structure.
iterator operation takes time proportional to the current size or the queue.
For additional documentation, see Section 2.4 of
Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Type parameters
-
E
the generic type of key on this priority queue
Constructors
constructor
-
Construct priority queue.
Parameters
-
comparator for the queue elements.
-
Default value maxPQ: boolean = true
true if this queue should be MaxPriorityQueue, and false if this queue
should be MinPriorityQueue. Default value is true.
-
Default value keys: E[] = []
elements to put in this queue. Default value is empty array.
Properties
Private comparator
comparator for the queue elements.
Private inOrder
inOrder: function
Type declaration
-
- (i: number, j: number): boolean
-
Parameters
Returns boolean
Private maxPQ
maxPQ: boolean
true if this queue should be MaxPriorityQueue, and false if this queue
should be MinPriorityQueue. Default value is true.
Private pq
pq: E[] = [undefined as any]
Methods
enqueue
-
Parameters
Returns Queue<E>
every
- every(p: function): boolean
-
Parameters
-
p: function
-
-
Parameters
Returns boolean
Returns boolean
Private exch
- exch(i: number, j: number): void
filter
-
Parameters
-
p: function
-
-
Parameters
Returns boolean
find
- find(p: function): E | undefined
-
Parameters
-
p: function
-
-
Parameters
Returns boolean
Returns E
|
undefined
forEach
- forEach(f: function): void
Private greaterInOrder
- greaterInOrder(i: number, j: number): boolean
-
Parameters
Returns boolean
Private lessInOrder
- lessInOrder(i: number, j: number): boolean
-
Parameters
Returns boolean
map
-
Type parameters
Parameters
reduce
- reduce<A>(r: function, initialValue: A): A
-
Type parameters
Parameters
-
r: function
-
- (accumulator: A, currentElement: E): A
-
Parameters
-
accumulator: A
-
currentElement: E
Returns A
-
initialValue: A
Returns A
some
- some(p: function): boolean
-
Parameters
-
p: function
-
-
Parameters
Returns boolean
Returns boolean