(index, score)
| 9 | } |
| 10 | |
| 11 | push(index, score) { |
| 12 | if (this.size < this.k) { |
| 13 | this.indices[this.size] = index; |
| 14 | this.scores[this.size] = score; |
| 15 | this.size += 1; |
| 16 | this._siftUp(this.size - 1); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | if (score <= this.scores[0]) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | this.indices[0] = index; |
| 25 | this.scores[0] = score; |
| 26 | this._siftDown(0); |
| 27 | } |
| 28 | |
| 29 | toSortedArray(mapper) { |
| 30 | const results = []; |