We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 778787a commit 4240992Copy full SHA for 4240992
1 file changed
src/data-structures/heap.js
@@ -76,6 +76,18 @@
76
return parent;
77
};
78
79
+ /**
80
+ * Updates given node. This operation is useful
81
+ * in algorithms like Dijkstra, A* where we need
82
+ * to decrease/increase the value of givne node.
83
+ */
84
+ Heap.prototype.update = function (node) {
85
+ var idx = this._heap.indexOf(node);
86
+ if (idx >= 0) {
87
+ this.changeKey(idx, node);
88
+ }
89
+ };
90
+
91
/**
92
* Adds new element to the heap. Complexity O(log n).
93
*
0 commit comments