| 701 | } |
| 702 | |
| 703 | remove( |
| 704 | edit: number, |
| 705 | shift: number, |
| 706 | hash: number, |
| 707 | key: K, |
| 708 | removed: { value: boolean } |
| 709 | ): Node<K, V> | undefined { |
| 710 | const idx = mask(hash, shift) |
| 711 | const child = this.children[idx] |
| 712 | |
| 713 | if (!child) { |
| 714 | return this |
| 715 | } |
| 716 | |
| 717 | const newChild = child.remove(edit, shift + SHIFT, hash, key, removed) |
| 718 | |
| 719 | if (!removed.value) { |
| 720 | return this |
| 721 | } |
| 722 | |
| 723 | const newCount = this.count - (newChild ? 0 : 1) |
| 724 | |
| 725 | if (newCount < MIN_ARRAY_NODE) { |
| 726 | return this.pack(edit, idx, newChild) |
| 727 | } |
| 728 | |
| 729 | if (child === newChild) { |
| 730 | return this |
| 731 | } |
| 732 | |
| 733 | if (this.canEdit(edit)) { |
| 734 | this.children[idx] = newChild |
| 735 | if (!newChild) { |
| 736 | this.count = newCount |
| 737 | } |
| 738 | this._size = undefined |
| 739 | return this |
| 740 | } |
| 741 | |
| 742 | const newChildren = [...this.children] |
| 743 | newChildren[idx] = newChild |
| 744 | return new ArrayNode(edit, newCount, newChildren) |
| 745 | } |
| 746 | |
| 747 | private pack( |
| 748 | edit: number, |