MCPcopy Index your code
hub / github.com/react/react / siftUp

Function siftUp

packages/scheduler/src/SchedulerMinHeap.js:42–57  ·  view source on GitHub ↗
(heap: Heap<T>, node: T, i: number)

Source from the content-addressed store, hash-verified

40}
41
42function siftUp<T: Node>(heap: Heap<T>, node: T, i: number): void {
43 let index = i;
44 while (index > 0) {
45 const parentIndex = (index - 1) >>> 1;
46 const parent = heap[parentIndex];
47 if (compare(parent, node) > 0) {
48 // The parent is larger. Swap positions.
49 heap[parentIndex] = node;
50 heap[index] = parent;
51 index = parentIndex;
52 } else {
53 // The parent is smaller. Exit.
54 return;
55 }
56 }
57}
58
59function siftDown<T: Node>(heap: Heap<T>, node: T, i: number): void {
60 let index = i;

Callers 1

pushFunction · 0.85

Calls 1

compareFunction · 0.85

Tested by

no test coverage detected