MCPcopy Create free account
hub / github.com/codemix/graph / bubbleDown

Method bubbleDown

packages/graph/src/Steps.ts:5012–5037  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

5010 }
5011
5012 private bubbleDown(index: number): void {
5013 while (true) {
5014 let minIndex = index;
5015 const leftChild = 2 * index + 1;
5016 const rightChild = 2 * index + 2;
5017
5018 if (
5019 leftChild < this.heap.length &&
5020 this.compareFn(this.heap[leftChild]!, this.heap[minIndex]!) < 0
5021 ) {
5022 minIndex = leftChild;
5023 }
5024
5025 if (
5026 rightChild < this.heap.length &&
5027 this.compareFn(this.heap[rightChild]!, this.heap[minIndex]!) < 0
5028 ) {
5029 minIndex = rightChild;
5030 }
5031
5032 if (minIndex === index) break;
5033
5034 [this.heap[index], this.heap[minIndex]] = [this.heap[minIndex]!, this.heap[index]!];
5035 index = minIndex;
5036 }
5037 }
5038}
5039
5040/**

Callers 1

popMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected