Navigation, Hashing, and Merkle Properties
Introduction
Navigation Algorithm
std::shared_ptr<SHAMapLeafNode> findLeaf(uint256 key) {
std::shared_ptr<SHAMapTreeNode> node = mRoot;
for (int depth = 0; depth < 64; ++depth) {
// Is this a leaf?
if (auto leaf = std::dynamic_pointer_cast<SHAMapLeafNode>(node)) {
return leaf;
}
// Must be inner node
auto inner = std::dynamic_pointer_cast<SHAMapInnerNode>(node);
// Extract 4-bit chunk (nibble) at position 'depth'
int branch = key.nthNibble(depth);
// Get child node at that branch
node = inner->getChild(branch);
if (!node) {
// Child doesn't exist - key not in tree
return nullptr;
}
}
return nullptr; // Key not found
}Hash Computation
Merkle Tree Properties
Mutable Tree Operations
Summary
Last updated

