MCPcopy Create free account
hub / github.com/p2r3/convert / siftupUsingComparator

Method siftupUsingComparator

src/PriorityQueue.ts:38–53  ·  view source on GitHub ↗

* siftup of heap

(k: number, item: T)

Source from the content-addressed store, hash-verified

36 * siftup of heap
37 */
38 private siftupUsingComparator(k: number, item: T): void {
39 while (k > 0) {
40 // find the parent
41 const parent = (k - 1) >>> 1;
42 const e = this._queue[parent] as T;
43 // compare item with it parent, if item's priority less, break siftup and insert
44 if (this._comparator!(item, e) >= 0) {
45 break;
46 }
47 // if item's priority more, make it's parent sink and proceed siftup
48 this._queue[k] = e;
49 k = parent;
50 }
51 // if k === 0, then we directly insert it
52 this._queue[k] = item;
53 }
54
55 private siftupComparable(k: number, item: T): void {
56 while (k > 0) {

Callers 1

siftupMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected