Simplify initial node-finding loop in SHAMap::upper_bound

This commit is contained in:
Howard Hinnant
2015-12-09 17:14:40 -05:00
committed by Nik Bougalis
parent 05ac32064f
commit bdd733bc0b

View File

@@ -575,22 +575,17 @@ SHAMap::upper_bound(uint256 const& id) const
NodeStack stack;
auto node = root_.get();
auto nodeID = SHAMapNodeID{};
auto foundLeaf = true;
stack.push ({node, nodeID});
while (!node->isLeaf())
{
stack.push ({node, nodeID});
auto branch = nodeID.selectBranch(id);
auto inner = static_cast<SHAMapInnerNode*>(node);
if (inner->isEmptyBranch(branch))
{
foundLeaf = false;
break;
}
node = descendThrow(inner, branch);
nodeID = nodeID.getChildNodeID(branch);
stack.push ({node, nodeID});
}
if (foundLeaf)
stack.push({node, nodeID});
while (!stack.empty())
{
std::tie(node, nodeID) = stack.top();