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

Method set

packages/effect/src/internal/hashMap.ts:512–565  ·  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

510 }
511
512 set(
513 edit: number,
514 shift: number,
515 hash: number,
516 key: K,
517 value: V,
518 added: { value: boolean }
519 ): Node<K, V> {
520 if (this.canEdit(edit)) this._hash = undefined
521 const bit = bitpos(hash, shift)
522 const idx = index(this.bitmap, bit)
523
524 if ((this.bitmap & bit) !== 0) {
525 // Existing child - update it
526 const child = this.children[idx]
527 const newChild = child.set(edit, shift + SHIFT, hash, key, value, added)
528 if (child === newChild) {
529 return this
530 }
531
532 if (this.canEdit(edit)) {
533 this.children[idx] = newChild
534 return this
535 }
536
537 const newChildren = this.children.slice()
538 newChildren[idx] = newChild
539 return new IndexedNode(edit, this.bitmap, newChildren)
540 } else {
541 // New child - insert
542 added.value = true
543 const newChild = new LeafNode(edit, hash, key, value)
544 const newBitmap = this.bitmap | bit
545
546 if (this.canEdit(edit)) {
547 this.children.splice(idx, 0, newChild)
548 this.bitmap = newBitmap
549 this._size = undefined
550
551 if (this.children.length > MAX_INDEX_NODE) {
552 return this.expand(edit, newBitmap, this.children)
553 }
554 return this
555 }
556
557 const newChildren = insertAt(this.children, idx, newChild)
558
559 if (newChildren.length > MAX_INDEX_NODE) {
560 return this.expand(edit, newBitmap, newChildren)
561 }
562
563 return new IndexedNode(edit, newBitmap, newChildren)
564 }
565 }
566
567 remove(
568 edit: number,

Callers

nothing calls this directly

Calls 7

expandMethod · 0.95
bitposFunction · 0.85
insertAtFunction · 0.85
canEditMethod · 0.80
sliceMethod · 0.80
indexFunction · 0.70
setMethod · 0.65

Tested by

no test coverage detected