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

Method sinkUsingComparator

src/PriorityQueue.ts:76–97  ·  view source on GitHub ↗
(k: number, item: T)

Source from the content-addressed store, hash-verified

74 }
75
76 private sinkUsingComparator(k: number, item: T): void {
77 const half = this._size >>> 1;
78 while (k < half) {
79 let child = (k << 1) + 1;
80 let object = this._queue[child];
81 const right = child + 1;
82 // compare left right child, assign child the bigger one
83 if (
84 right < this._size &&
85 this._comparator!(object, this._queue[right]) > 0
86 ) {
87 object = this._queue[(child = right)];
88 }
89 // compare item and child if bigger is item, break
90 if (this._comparator!(item, object) <= 0) {
91 break;
92 }
93 this._queue[k] = object!;
94 k = child;
95 }
96 this._queue[k] = item;
97 }
98
99 private sinkComparable(k: number, item: T): void {
100 const half = this._size >>> 1;

Callers 1

sinkMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected