(
key: K,
value: V,
overwrite: boolean | undefined,
tree: BTree<K, V>,
)
| 533 | // Leaf Node: set & node splitting ////////////////////////////////////////// |
| 534 | |
| 535 | set( |
| 536 | key: K, |
| 537 | value: V, |
| 538 | overwrite: boolean | undefined, |
| 539 | tree: BTree<K, V>, |
| 540 | ): boolean | BNode<K, V> { |
| 541 | let i = this.indexOf(key, -1, tree._compare) |
| 542 | if (i < 0) { |
| 543 | // key does not exist yet |
| 544 | i = ~i |
| 545 | tree._size++ |
| 546 | |
| 547 | if (this.keys.length < tree._maxNodeSize) { |
| 548 | return this.insertInLeaf(i, key, value, tree) |
| 549 | } else { |
| 550 | // This leaf node is full and must split |
| 551 | const newRightSibling = this.splitOffRightSide() |
| 552 | let target: BNode<K, V> = this |
| 553 | if (i > this.keys.length) { |
| 554 | i -= this.keys.length |
| 555 | target = newRightSibling |
| 556 | } |
| 557 | target.insertInLeaf(i, key, value, tree) |
| 558 | return newRightSibling |
| 559 | } |
| 560 | } else { |
| 561 | // Key already exists |
| 562 | if (overwrite !== false) { |
| 563 | if (value !== undefined) this.reifyValues() |
| 564 | // usually this is a no-op, but some users may wish to edit the key |
| 565 | this.keys[i] = key |
| 566 | this.values[i] = value |
| 567 | } |
| 568 | return false |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | reifyValues() { |
| 573 | if (this.values === undefVals) |
nothing calls this directly
no test coverage detected