diff --git a/VersionedMap.cpp b/VersionedMap.cpp index 52c34a5..570ec6f 100644 --- a/VersionedMap.cpp +++ b/VersionedMap.cpp @@ -1019,6 +1019,16 @@ struct VersionedMap::Iterator::Impl { result.mutations[1] = mutations[1]; finger.copyTo(result.finger); } + + 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; + } }; VersionedMap::Iterator::~Iterator() { @@ -1173,14 +1183,10 @@ VersionedMap::Iterator VersionedMap::Iterator::operator--(int) { } bool VersionedMap::Iterator::operator==(const Iterator &other) const { - assert(impl->map == other.impl->map); - assert(impl->version == other.impl->version); - if (impl->finger.searchPathSize() == 0 || - other.impl->finger.searchPathSize() == 0) { - return impl->finger.searchPathSize() == other.impl->finger.searchPathSize(); + if (impl == nullptr || other.impl == nullptr) { + return impl == other.impl; } - return impl->finger.backNode() == other.impl->finger.backNode() && - impl->mutationIndex == other.impl->mutationIndex; + return impl->equals(*other.impl); } void VersionedMap::Impl::firstGeq(const Key *key, const int64_t *version, @@ -1242,7 +1248,10 @@ void VersionedMap::Impl::firstGeq(const Key *key, const int64_t *version, } bool VersionedMap::Iterator::operator!=(const Iterator &other) const { - return !(*this == other); + if (impl == nullptr || other.impl == nullptr) { + return impl != other.impl; + } + return !impl->equals(*other.impl); } int VersionedMap::Iterator::cmp() const { return impl->cmp; }