Add operator== for Finger

This commit is contained in:
2024-05-24 13:38:41 -07:00
parent 8f8ea62ed5
commit d51c58e6d5

View File

@@ -449,6 +449,21 @@ struct Finger {
Finger(Finger &&) = delete;
Finger &operator=(Finger &&) = delete;
bool operator==(const Finger &other) const {
bool result = searchPathSize_ == other.searchPathSize_ &&
(searchPathSize_ == 0 || backNode() == other.backNode());
#ifndef NDEBUG
auto expected = searchPathSize_ == other.searchPathSize_ &&
memcmp(searchPath, other.searchPath,
searchPathSize_ * sizeof(searchPath[0])) == 0 &&
(searchPathSize_ == 0 ||
memcmp(direction + 1, other.direction + 1,
(searchPathSize_ - 1) * sizeof(direction[0])) == 0);
assert(result == expected);
#endif
return result;
}
private:
uint32_t searchPath[kPathLengthUpperBound];
bool direction[kPathLengthUpperBound];
@@ -951,11 +966,7 @@ struct VersionedMap::Iterator::Impl {
bool equals(const Impl &other) const {
assert(map == other.map);
assert(version == other.version);
if (finger.searchPathSize() == 0 || other.finger.searchPathSize() == 0) {
return finger.searchPathSize() == other.finger.searchPathSize();
}
return finger.backNode() == other.finger.backNode() &&
mutationIndex == other.mutationIndex;
return finger == other.finger && mutationIndex == other.mutationIndex;
}
};