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; NodeStack stack;
auto node = root_.get(); auto node = root_.get();
auto nodeID = SHAMapNodeID{}; auto nodeID = SHAMapNodeID{};
auto foundLeaf = true; stack.push ({node, nodeID});
while (!node->isLeaf()) while (!node->isLeaf())
{ {
stack.push ({node, nodeID});
auto branch = nodeID.selectBranch(id); auto branch = nodeID.selectBranch(id);
auto inner = static_cast<SHAMapInnerNode*>(node); auto inner = static_cast<SHAMapInnerNode*>(node);
if (inner->isEmptyBranch(branch)) if (inner->isEmptyBranch(branch))
{
foundLeaf = false;
break; break;
}
node = descendThrow(inner, branch); node = descendThrow(inner, branch);
nodeID = nodeID.getChildNodeID(branch); nodeID = nodeID.getChildNodeID(branch);
stack.push ({node, nodeID});
} }
if (foundLeaf)
stack.push({node, nodeID});
while (!stack.empty()) while (!stack.empty())
{ {
std::tie(node, nodeID) = stack.top(); std::tie(node, nodeID) = stack.top();