mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Binary-Heap: update in-place
This commit is contained in:
@@ -130,14 +130,16 @@ _.extend(MaxHeap.prototype, {
|
||||
if (self.has(id)) {
|
||||
if (self.get(id) === value)
|
||||
return;
|
||||
else {
|
||||
self.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
self._heapIdx.set(id, self._heap.length);
|
||||
self._heap.push({ id: id, value: value });
|
||||
self._upHeap(self._heap.length - 1);
|
||||
var idx = self._heapIdx.get(id);
|
||||
self._heap[idx].value = value;
|
||||
self._upHeap(idx);
|
||||
self._downHeap(idx);
|
||||
} else {
|
||||
self._heapIdx.set(id, self._heap.length);
|
||||
self._heap.push({ id: id, value: value });
|
||||
self._upHeap(self._heap.length - 1);
|
||||
}
|
||||
},
|
||||
remove: function (id) {
|
||||
var self = this;
|
||||
|
||||
Reference in New Issue
Block a user