| 678 | } |
| 679 | |
| 680 | set( |
| 681 | edit: number, |
| 682 | shift: number, |
| 683 | hash: number, |
| 684 | key: K, |
| 685 | value: V, |
| 686 | added: { value: boolean } |
| 687 | ): Node<K, V> { |
| 688 | if (this.canEdit(edit)) this._hash = undefined |
| 689 | const idx = mask(hash, shift) |
| 690 | const child = this.children[idx] |
| 691 | |
| 692 | if (child) { |
| 693 | const newChild = child.set(edit, shift + SHIFT, hash, key, value, added) |
| 694 | if (child === newChild) { |
| 695 | return this |
| 696 | } |
| 697 | |
| 698 | if (this.canEdit(edit)) { |
| 699 | this.children[idx] = newChild |
| 700 | return this |
| 701 | } |
| 702 | |
| 703 | const newChildren = this.children.slice() |
| 704 | newChildren[idx] = newChild |
| 705 | return new ArrayNode(edit, this.count, newChildren) |
| 706 | } else { |
| 707 | added.value = true |
| 708 | const newChild = new LeafNode(edit, hash, key, value) |
| 709 | |
| 710 | if (this.canEdit(edit)) { |
| 711 | this.children[idx] = newChild |
| 712 | this.count++ |
| 713 | this._size = undefined |
| 714 | return this |
| 715 | } |
| 716 | |
| 717 | const newChildren = this.children.slice() |
| 718 | newChildren[idx] = newChild |
| 719 | return new ArrayNode(edit, this.count + 1, newChildren) |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | remove( |
| 724 | edit: number, |