From d51c58e6d52265b2910bfb3090af8539f8a5a204 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 24 May 2024 13:38:41 -0700 Subject: [PATCH] Add operator== for Finger --- VersionedMap.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/VersionedMap.cpp b/VersionedMap.cpp index f800dba..17b6276 100644 --- a/VersionedMap.cpp +++ b/VersionedMap.cpp @@ -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; } };