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

Function setHash

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

Source from the content-addressed store, hash-verified

978})
979
980const 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 */
1006export const set = dual<

Callers 2

hashMap.tsFile · 0.85

Calls 1

setMethod · 0.65

Tested by

no test coverage detected