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

Class ArrayNode

packages/effect/src/internal/hashMap.ts:623–802  ·  view source on GitHub ↗

@internal

Source from the content-addressed store, hash-verified

621
622/** @internal */
623class ArrayNode<K, V> extends Node<K, V> {
624 readonly _tag = "ArrayNode"
625
626 edit: number
627 private _size: number | undefined
628 count: number
629 children: Array<Node<K, V> | undefined>
630
631 constructor(
632 edit: number,
633 count: number,
634 children: Array<Node<K, V> | undefined>
635 ) {
636 super()
637 this.edit = edit
638 this.count = count
639 this.children = children
640 }
641
642 get size(): number {
643 if (this._size === undefined) {
644 this._size = this.children.reduce<number>((acc, child) => acc + (child?.size ?? 0), 0)
645 }
646 return this._size
647 }
648
649 get(shift: number, hash: number, key: K): Option.Option<V> {
650 const idx = mask(hash, shift)
651 const child = this.children[idx]
652 return child ? child.get(shift + SHIFT, hash, key) : Option.none()
653 }
654
655 has(shift: number, hash: number, key: K): boolean {
656 const idx = mask(hash, shift)
657 const child = this.children[idx]
658 return child ? child.has(shift + SHIFT, hash, key) : false
659 }
660
661 set(
662 edit: number,
663 shift: number,
664 hash: number,
665 key: K,
666 value: V,
667 added: { value: boolean }
668 ): Node<K, V> {
669 const idx = mask(hash, shift)
670 const child = this.children[idx]
671
672 if (child) {
673 const newChild = child.set(edit, shift + SHIFT, hash, key, value, added)
674 if (child === newChild) {
675 return this
676 }
677
678 if (this.canEdit(edit)) {
679 this.children[idx] = newChild
680 return this

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected