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

Class IndexedNode

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

@internal

Source from the content-addressed store, hash-verified

421
422/** @internal */
423class IndexedNode<K, V> extends Node<K, V> {
424 readonly _tag = "IndexedNode"
425
426 edit: number
427 private _size: number | undefined
428 bitmap: number
429 children: Array<Node<K, V>>
430
431 constructor(
432 edit: number,
433 bitmap: number,
434 children: Array<Node<K, V>>
435 ) {
436 super()
437 this.edit = edit
438 this.bitmap = bitmap
439 this.children = children
440 }
441
442 get size(): number {
443 if (this._size === undefined) {
444 this._size = this.children.reduce((acc, child) => acc + child.size, 0)
445 }
446 return this._size
447 }
448
449 get(shift: number, hash: number, key: K): Option.Option<V> {
450 const bit = bitpos(hash, shift)
451 if ((this.bitmap & bit) === 0) {
452 return Option.none()
453 }
454 const idx = index(this.bitmap, bit)
455 return this.children[idx].get(shift + SHIFT, hash, key)
456 }
457
458 has(shift: number, hash: number, key: K): boolean {
459 const bit = bitpos(hash, shift)
460 if ((this.bitmap & bit) === 0) {
461 return false
462 }
463 const idx = index(this.bitmap, bit)
464 return this.children[idx].has(shift + SHIFT, hash, key)
465 }
466
467 set(
468 edit: number,
469 shift: number,
470 hash: number,
471 key: K,
472 value: V,
473 added: { value: boolean }
474 ): Node<K, V> {
475 const bit = bitpos(hash, shift)
476 const idx = index(this.bitmap, bit)
477
478 if ((this.bitmap & bit) !== 0) {
479 // Existing child - update it
480 const child = this.children[idx]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected