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->peekData() != otherMapItem->peekData())
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()->peekData() !=
160 other->peekItem()->peekData())
163 ours->peekItem()->key(),
164 DeltaRef(ours->peekItem(), other->peekItem())));
172 ours->peekItem()->key(),
180 other->peekItem()->key(),
183 other->peekItem())));
188 else if (ourNode->isInner() && otherNode->isLeaf())
193 ours, other->peekItem(),
true, differences, maxCount))
196 else if (ourNode->isLeaf() && otherNode->isInner())
201 other, ours->peekItem(),
false, differences, maxCount))
204 else if (ourNode->isInner() && otherNode->isInner())
208 for (
int i = 0; i < 16; ++i)
209 if (ours->getChildHash(i) != other->getChildHash(i))
211 if (other->isEmptyBranch(i))
223 else if (ours->isEmptyBranch(i))
237 {descendThrow(ours, i),
252 if (!root_->isInner())
258 nodeStack.
push(std::static_pointer_cast<SHAMapInnerNode>(root_));
260 while (!nodeStack.
empty())
265 for (
int i = 0; i < 16; ++i)
267 if (!node->isEmptyBranch(i))
270 descendNoStore(node, i);
274 if (nextNode->isInner())
276 std::static_pointer_cast<SHAMapInnerNode>(
281 missingNodes.
emplace_back(type_, node->getChildHash(i));
282 if (--maxMissing <= 0)