mergeIntoNode merges a key/value pair into an existing node. Caller must verify that node's keyHash is not equal to keyHash.
(node mapLeafNode[K, V], shift uint, keyHash uint32, key K, value V)
| 1410 | // mergeIntoNode merges a key/value pair into an existing node. |
| 1411 | // Caller must verify that node's keyHash is not equal to keyHash. |
| 1412 | func mergeIntoNode[K, V any](node mapLeafNode[K, V], shift uint, keyHash uint32, key K, value V) mapNode[K, V] { |
| 1413 | idx1 := (node.keyHashValue() >> shift) & mapNodeMask |
| 1414 | idx2 := (keyHash >> shift) & mapNodeMask |
| 1415 | |
| 1416 | // Recursively build branch nodes to combine the node and its key. |
| 1417 | other := &mapBitmapIndexedNode[K, V]{bitmap: (1 << idx1) | (1 << idx2)} |
| 1418 | if idx1 == idx2 { |
| 1419 | other.nodes = []mapNode[K, V]{mergeIntoNode(node, shift+mapNodeBits, keyHash, key, value)} |
| 1420 | } else { |
| 1421 | if newNode := newMapValueNode(keyHash, key, value); idx1 < idx2 { |
| 1422 | other.nodes = []mapNode[K, V]{node, newNode} |
| 1423 | } else { |
| 1424 | other.nodes = []mapNode[K, V]{newNode, node} |
| 1425 | } |
| 1426 | } |
| 1427 | return other |
| 1428 | } |
| 1429 | |
| 1430 | // mapEntry represents a single key/value pair. |
| 1431 | type mapEntry[K, V any] struct { |
no test coverage detected
searching dependent graphs…