add method
Adds an element
with a priority
to the queue.
The priority
must be a finite number.
The element is added to the queue in O(log n)
time.
Implementation
void add(int element, double priority) {
var pos = _length++;
while (pos > 0) {
final parent = (pos - 1) >> 1;
if (priority >= _priorities[parent]) {
break;
}
_set(
_ids[parent],
_priorities[parent],
index: pos,
);
pos = parent;
}
_set(
element,
priority,
index: pos,
);
}