mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Fix stack bug in upper_bound
This commit is contained in:
committed by
Edward Hennis
parent
ffbcb96eff
commit
44e4a50050
@@ -501,7 +501,11 @@ SHAMap::peekFirstItem(NodeStack& stack) const
|
|||||||
stack.push({root_.get(), SHAMapNodeID{}});
|
stack.push({root_.get(), SHAMapNodeID{}});
|
||||||
SHAMapTreeNode* node = firstBelow(root_.get(), stack);
|
SHAMapTreeNode* node = firstBelow(root_.get(), stack);
|
||||||
if (!node)
|
if (!node)
|
||||||
|
{
|
||||||
|
while (!stack.empty())
|
||||||
|
stack.pop();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
return node->peekItem().get();
|
return node->peekItem().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,11 +608,9 @@ SHAMap::upper_bound(uint256 const& id) const
|
|||||||
auto leaf = static_cast<SHAMapTreeNode*>(node);
|
auto leaf = static_cast<SHAMapTreeNode*>(node);
|
||||||
if (leaf->peekItem()->key() > id)
|
if (leaf->peekItem()->key() > id)
|
||||||
return const_iterator(this, leaf->peekItem().get(), std::move(stack));
|
return const_iterator(this, leaf->peekItem().get(), std::move(stack));
|
||||||
stack.pop();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stack.pop();
|
|
||||||
auto inner = static_cast<SHAMapInnerNode*>(node);
|
auto inner = static_cast<SHAMapInnerNode*>(node);
|
||||||
for (auto branch = nodeID.selectBranch(id) + 1; branch < 16; ++branch)
|
for (auto branch = nodeID.selectBranch(id) + 1; branch < 16; ++branch)
|
||||||
{
|
{
|
||||||
@@ -625,6 +627,7 @@ SHAMap::upper_bound(uint256 const& id) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stack.pop();
|
||||||
}
|
}
|
||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user