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

Method set

packages/effect/src/internal/hashMap.ts:331–374  ·  view source on GitHub ↗
(
    edit: number,
    shift: number,
    hash: number,
    key: K,
    value: V,
    added: { value: boolean }
  )

Source from the content-addressed store, hash-verified

329 }
330
331 set(
332 edit: number,
333 shift: number,
334 hash: number,
335 key: K,
336 value: V,
337 added: { value: boolean }
338 ): Node<K, V> {
339 if (this.hash !== hash) {
340 added.value = true
341 // Need to merge this collision node with new leaf
342 return mergeLeaves(
343 edit,
344 shift,
345 this.hash,
346 this,
347 hash,
348 new LeafNode(edit, hash, key, value)
349 )
350 }
351
352 // Same hash - update or add to collision list
353 for (let i = 0; i < this.entries.length; i++) {
354 if (Equal_.equals(this.entries[i][0], key)) {
355 if (Equal_.equals(this.entries[i][1], value)) {
356 return this
357 }
358 if (this.canEdit(edit)) {
359 this.entries[i] = [key, value]
360 return this
361 }
362 const newEntries = [...this.entries]
363 newEntries[i] = [key, value]
364 return new CollisionNode(edit, this.hash, newEntries)
365 }
366 }
367
368 added.value = true
369 if (this.canEdit(edit)) {
370 this.entries.push([key, value])
371 return this
372 }
373 return new CollisionNode(edit, this.hash, [...this.entries, [key, value]])
374 }
375
376 remove(
377 edit: number,

Callers

nothing calls this directly

Calls 4

mergeLeavesFunction · 0.85
equalsMethod · 0.80
canEditMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected