| 627 | } |
| 628 | |
| 629 | class HashArrayMapNode<K, V> { |
| 630 | constructor( |
| 631 | public ownerID: OwnerID, |
| 632 | public count: number, |
| 633 | public nodes: Array<MapNode<K, V>> |
| 634 | ) {} |
| 635 | |
| 636 | get(shift: number, keyHash: number, key: K, notSetValue?: V): V | undefined { |
| 637 | if (keyHash === undefined) { |
| 638 | keyHash = hash(key) |
| 639 | } |
| 640 | const idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK |
| 641 | const node = this.nodes[idx] |
| 642 | return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue |
| 643 | } |
| 644 | |
| 645 | update( |
| 646 | ownerID: OwnerID, |
| 647 | shift: number, |
| 648 | keyHash: number, |
| 649 | key: K, |
| 650 | value: V, |
| 651 | didChangeSize?: Ref, |
| 652 | didAlter?: Ref |
| 653 | ) { |
| 654 | if (keyHash === undefined) { |
| 655 | keyHash = hash(key) |
| 656 | } |
| 657 | const idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK |
| 658 | const removed = value === NOT_SET |
| 659 | const nodes = this.nodes |
| 660 | const node = nodes[idx] |
| 661 | |
| 662 | if (removed && !node) { |
| 663 | return this |
| 664 | } |
| 665 | |
| 666 | const newNode = updateNode( |
| 667 | node, |
| 668 | ownerID, |
| 669 | shift + SHIFT, |
| 670 | keyHash, |
| 671 | key, |
| 672 | value, |
| 673 | didChangeSize, |
| 674 | didAlter |
| 675 | ) |
| 676 | if (newNode === node) { |
| 677 | return this |
| 678 | } |
| 679 | |
| 680 | let newCount = this.count |
| 681 | if (!node) { |
| 682 | newCount++ |
| 683 | } else if (!newNode) { |
| 684 | newCount-- |
| 685 | if (newCount < MIN_HASH_ARRAY_MAP_SIZE) { |
| 686 | return packNodes(ownerID, nodes, newCount, idx) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…