Fix building heap from array

This commit is contained in:
Slava Kim
2014-02-20 22:38:56 -08:00
parent 19eeff650a
commit d87b18a56e

View File

@@ -48,7 +48,8 @@ _.extend(MaxHeap.prototype, {
self._heapIdx.set(o.id, i);
});
for (var i = parentIdx(data.length); i >= 0; i--)
// start from the first non-leaf - the parent of the last leaf
for (var i = parentIdx(data.length - 1); i >= 0; i--)
self._downHeap(i);
},