Binary Heap
Tags | Perfomance |
---|
It heapify each element when changing values, so there are better ways to do it.
```
insert(key: string, value: number) {
if (this.nodes.has(key)) {
return;
}
const node = new Node(key, value);
this.heap.insert(node);
this.nodes.set(key, node);
this.heap.heapifyAll(); // TODO
}
changeKey(key: string, value: number) {
if (!this.nodes.has(key)) {
return;
}
let node = this.nodes.get(key);
node = new Node(node.key, value, node.position);
this.nodes.set(key, node);
this.heap.set(node.position, node);
this.heap.heapifyAll(); // TODO
}