* Move children from `rhs` into this. * `rhs` must be part of this tree, and be removed from it after this call * (otherwise isShared for its children could be incorrect).
(rhs: BNode<K, V>, maxNodeSize: number)
| 978 | * (otherwise isShared for its children could be incorrect). |
| 979 | */ |
| 980 | mergeSibling(rhs: BNode<K, V>, maxNodeSize: number) { |
| 981 | // assert !this.isShared; |
| 982 | const oldLength = this.keys.length |
| 983 | this.keys.push.apply(this.keys, rhs.keys) |
| 984 | const rhsChildren = (rhs as any as BNodeInternal<K, V>).children |
| 985 | this.children.push.apply(this.children, rhsChildren) |
| 986 | |
| 987 | if (rhs.isShared && !this.isShared) { |
| 988 | // All children of a shared node are implicitly shared, and since their new |
| 989 | // parent is not shared, they must now be explicitly marked as shared. |
| 990 | for (const child of rhsChildren) child.isShared = true |
| 991 | } |
| 992 | |
| 993 | // If our children are themselves almost empty due to a mass-delete, |
| 994 | // they may need to be merged too (but only the oldLength-1 and its |
| 995 | // right sibling should need this). |
| 996 | this.tryMerge(oldLength - 1, maxNodeSize) |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | // Optimization: this array of `undefined`s is used instead of a normal |