* siftup of heap
(k: number, item: T)
| 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) { |