diff options
Diffstat (limited to 'src/BlockState.cpp')
-rw-r--r-- | src/BlockState.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/BlockState.cpp b/src/BlockState.cpp index 4e2607bd3..8ee87c50f 100644 --- a/src/BlockState.cpp +++ b/src/BlockState.cpp @@ -83,6 +83,52 @@ BlockState::BlockState(const BlockState & aCopyFrom, const std::map<AString, ASt +bool BlockState::operator <(const BlockState & aOther) const +{ + // Fast-return this using checksum + if (mChecksum != aOther.mChecksum) + { + return (mChecksum < aOther.mChecksum); + } + + // Can fast-return this due to how comparison works + if (mState.size() != aOther.mState.size()) + { + return (mState.size() < aOther.mState.size()); + } + + auto itA = mState.begin(); + auto itOther = aOther.mState.begin(); + + // don't need to check itOther, size checks above ensure size(A) == size(O) + while (itA != mState.end()) + { + { + const auto cmp = itA->first.compare(itOther->first); + if (cmp != 0) + { + return (cmp < 0); + } + } + { + const auto cmp = itA->second.compare(itOther->second); + if (cmp != 0) + { + return (cmp < 0); + } + } + + ++itA; + ++itOther; + } + + return false; +} + + + + + bool BlockState::operator ==(const BlockState & aOther) const { // Fast-fail if the checksums differ or differrent counts: |