MCPcopy Create free account
hub / github.com/esengine/esengine / sinkDown

Method sinkDown

packages/pathfinding/src/core/BinaryHeap.ts:129–154  ·  view source on GitHub ↗

* @zh 下沉操作 * @en Sink down operation

(index: number)

Source from the content-addressed store, hash-verified

127 * @en Sink down operation
128 */
129 private sinkDown(index: number): void {
130 const length = this.heap.length;
131 const item = this.heap[index];
132
133 while (true) {
134 const leftIndex = 2 * index + 1;
135 const rightIndex = 2 * index + 2;
136 let smallest = index;
137
138 if (leftIndex < length && this.compare(this.heap[leftIndex], this.heap[smallest]) < 0) {
139 smallest = leftIndex;
140 }
141
142 if (rightIndex < length && this.compare(this.heap[rightIndex], this.heap[smallest]) < 0) {
143 smallest = rightIndex;
144 }
145
146 if (smallest === index) {
147 break;
148 }
149
150 this.heap[index] = this.heap[smallest];
151 this.heap[smallest] = item;
152 index = smallest;
153 }
154 }
155}

Callers 2

popMethod · 0.95
updateMethod · 0.95

Calls 1

compareMethod · 0.45

Tested by

no test coverage detected