MCPcopy Create free account
hub / github.com/Effect-TS/effect / setHash

Function setHash

packages/effect/src/internal/hashMap.ts:1017–1040  ·  view source on GitHub ↗
(self: HashMap<K, V>, key: K, hash: number, value: V)

Source from the content-addressed store, hash-verified

1015})
1016
1017const 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 */
1043export const set = dual<

Callers 2

hashMap.tsFile · 0.85

Calls 1

setMethod · 0.65

Tested by

no test coverage detected