(self: HashMap<K, V>, key: K, hash: number, value: V)
| 978 | }) |
| 979 | |
| 980 | const setHash = <K, V>(self: HashMap<K, V>, key: K, hash: number, value: V): HashMap<K, V> => { |
| 981 | const impl = self as HashMapImpl<K, V> |
| 982 | const added = { value: false } |
| 983 | |
| 984 | // Pass edit context: use current edit if editable, otherwise NaN (never matches any edit) |
| 985 | const edit = impl._editable ? impl._edit : NaN |
| 986 | const newRoot = impl._root.set(edit, 0, hash, key, value, added) |
| 987 | |
| 988 | if (impl._editable) { |
| 989 | // In-place mutation |
| 990 | impl._root = newRoot |
| 991 | if (added.value) { |
| 992 | impl._size++ |
| 993 | } |
| 994 | return self |
| 995 | } |
| 996 | |
| 997 | // Immutable: create new instance if changed |
| 998 | if (impl._root === newRoot) { |
| 999 | return self |
| 1000 | } |
| 1001 | |
| 1002 | return new HashMapImpl(false, impl._edit, newRoot, impl._size + (added.value ? 1 : 0)) |
| 1003 | } |
| 1004 | |
| 1005 | /** @internal */ |
| 1006 | export const set = dual< |
no test coverage detected