20 #include <ripple/basics/contract.h>
21 #include <ripple/shamap/SHAMap.h>
46 bool emptyBranch = !otherMapItem;
48 while (!nodeStack.
empty())
50 node = nodeStack.
top();
57 for (
int i = 0; i < 16; ++i)
58 if (!inner->isEmptyBranch(i))
66 if (emptyBranch || (item->key() != otherMapItem->key()))
81 else if (item->slice() != otherMapItem->slice())
86 item->key(),
DeltaRef(item, otherMapItem)));
89 item->key(),
DeltaRef(otherMapItem, item)));
124 SHAMap::compare(
SHAMap const& otherMap,
Delta& differences,
int maxCount)
const
131 assert(isValid() && otherMap.
isValid());
133 if (getHash() == otherMap.
getHash())
140 nodeStack.
push({root_.get(), otherMap.
root_.get()});
141 while (!nodeStack.
empty())
143 auto [ourNode, otherNode] = nodeStack.
top();
146 if (!ourNode || !otherNode)
149 Throw<SHAMapMissingNode>(type_,
uint256());
152 if (ourNode->isLeaf() && otherNode->isLeaf())
157 if (ours->peekItem()->key() == other->peekItem()->key())
159 if (ours->peekItem()->slice() != other->peekItem()->slice())
162 ours->peekItem()->key(),
163 DeltaRef(ours->peekItem(), other->peekItem())));
171 ours->peekItem()->key(),
179 other->peekItem()->key(),
182 other->peekItem())));
187 else if (ourNode->isInner() && otherNode->isLeaf())
192 ours, other->peekItem(),
true, differences, maxCount))
195 else if (ourNode->isLeaf() && otherNode->isInner())
200 other, ours->peekItem(),
false, differences, maxCount))
203 else if (ourNode->isInner() && otherNode->isInner())
207 for (
int i = 0; i < 16; ++i)
208 if (ours->getChildHash(i) != other->getChildHash(i))
210 if (other->isEmptyBranch(i))
222 else if (ours->isEmptyBranch(i))
236 {descendThrow(ours, i),
251 if (!root_->isInner())
257 nodeStack.
push(std::static_pointer_cast<SHAMapInnerNode>(root_));
259 while (!nodeStack.
empty())
264 for (
int i = 0; i < 16; ++i)
266 if (!node->isEmptyBranch(i))
269 descendNoStore(node, i);
273 if (nextNode->isInner())
275 std::static_pointer_cast<SHAMapInnerNode>(
280 missingNodes.
emplace_back(type_, node->getChildHash(i));
281 if (--maxMissing <= 0)