MCPcopy Index your code
hub / github.com/nodejs/node / percolateUp

Method percolateUp

lib/internal/priority_queue.js:71–92  ·  view source on GitHub ↗
(pos)

Source from the content-addressed store, hash-verified

69 }
70
71 percolateUp(pos) {
72 const heap = this.#heap;
73 const compare = this.#compare;
74 const setPosition = this.#setPosition;
75 const hasSetPosition = setPosition !== undefined;
76 const item = heap[pos];
77
78 while (pos > 1) {
79 const parent = pos >> 1;
80 const parentItem = heap[parent];
81 if (compare(parentItem, item) <= 0)
82 break;
83 heap[pos] = parentItem;
84 if (hasSetPosition)
85 setPosition(parentItem, pos);
86 pos = parent;
87 }
88
89 heap[pos] = item;
90 if (hasSetPosition)
91 setPosition(item, pos);
92 }
93
94 removeAt(pos) {
95 const heap = this.#heap;

Callers 2

insertMethod · 0.95
removeAtMethod · 0.95

Calls 2

setPositionFunction · 0.70
compareFunction · 0.50

Tested by

no test coverage detected