(self: HashMap<K, V>, key: K, hash: number, value: V)
| 1015 | }) |
| 1016 | |
| 1017 | const setHash = <K, V>(self: HashMap<K, V>, key: K, hash: number, value: V): HashMap<K, V> => { |
| 1018 | const impl = self as HashMapImpl<K, V> |
| 1019 | const added = { value: false } |
| 1020 | |
| 1021 | // Pass edit context: use current edit if editable, otherwise NaN (never matches any edit) |
| 1022 | const edit = impl._editable ? impl._edit : NaN |
| 1023 | const newRoot = impl._root.set(edit, 0, hash | 0, key, value, added) |
| 1024 | |
| 1025 | if (impl._editable) { |
| 1026 | // In-place mutation |
| 1027 | impl._root = newRoot |
| 1028 | if (added.value) { |
| 1029 | impl._size++ |
| 1030 | } |
| 1031 | return self |
| 1032 | } |
| 1033 | |
| 1034 | // Immutable: create new instance if changed |
| 1035 | if (impl._root === newRoot) { |
| 1036 | return self |
| 1037 | } |
| 1038 | |
| 1039 | return new HashMapImpl(false, impl._edit, newRoot, impl._size + (added.value ? 1 : 0)) |
| 1040 | } |
| 1041 | |
| 1042 | /** @internal */ |
| 1043 | export const set = dual< |
no test coverage detected