| 58 | |
| 59 | /** @internal */ |
| 60 | export class LeafNode<out K, out V> { |
| 61 | readonly _tag = "LeafNode" |
| 62 | |
| 63 | constructor( |
| 64 | readonly edit: number, |
| 65 | readonly hash: number, |
| 66 | readonly key: K, |
| 67 | public value: O.Option<V> |
| 68 | ) {} |
| 69 | |
| 70 | modify( |
| 71 | edit: number, |
| 72 | shift: number, |
| 73 | f: HashMap.UpdateFn<V>, |
| 74 | hash: number, |
| 75 | key: K, |
| 76 | size: SizeRef |
| 77 | ): Node<K, V> { |
| 78 | if (equals(key, this.key)) { |
| 79 | const v = f(this.value) |
| 80 | if (v === this.value) return this |
| 81 | else if (O.isNone(v)) { |
| 82 | --size.value |
| 83 | return new EmptyNode() |
| 84 | } |
| 85 | if (canEditNode(this, edit)) { |
| 86 | this.value = v |
| 87 | return this |
| 88 | } |
| 89 | return new LeafNode(edit, hash, key, v) |
| 90 | } |
| 91 | const v = f(O.none()) |
| 92 | if (O.isNone(v)) return this |
| 93 | ++size.value |
| 94 | return mergeLeaves( |
| 95 | edit, |
| 96 | shift, |
| 97 | this.hash, |
| 98 | this, |
| 99 | hash, |
| 100 | new LeafNode(edit, hash, key, v) |
| 101 | ) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** @internal */ |
| 106 | export class CollisionNode<out K, out V> { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…