Skip to content

Commit 2bf4a04

Browse files
fixed comments and bug
fixed some variable naming in comments. In extract(), now the removed element will be deleted from indexLookup and not set to null.
1 parent f244049 commit 2bf4a04

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/data_structures/priority_queue.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ Minimum Priority Queue implementation using heap.
33
44
elementHeap stores all element,
55
priorityHeap stores priority for given element,
6-
priority[i] stores priority of element[i].
7-
6+
priorityHeap[i] stores priority of elementHeap[i].
87
indexLookup stores index of element, so when priority is changed,
98
the top or bottom heap can be fixed from that position itself.
109
*/
@@ -48,7 +47,7 @@ class PriorityQueue {
4847
}
4948

5049
/*
51-
To fix bootom heap from position: idx
50+
To fix bottom heap from position: idx
5251
5352
Finds if left or right child is smaller, if true, swaps smallest element
5453
with parent and then calls fixBottomHeap for index of smallest element
@@ -123,7 +122,7 @@ class PriorityQueue {
123122
this._swap(0, this._size - 1);
124123
this._elementHeap.splice(-1, 1);
125124
this._priorityHeap.splice(-1, 1);
126-
this._indexLookup[_minPriorityItem] = null;
125+
delete this._indexLookup[_minPriorityItem];
127126
this._size--;
128127

129128
this._fixBottomHeap(0);

0 commit comments

Comments
 (0)