diff options
author | E14 <1640391+E14@users.noreply.github.com> | 2019-09-22 22:57:54 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2019-09-22 22:57:54 +0200 |
commit | d1c95742ddd83899bb35051de9d731d38aba80a4 (patch) | |
tree | 74be95b8f98def76a47c5fc81cca59a12bee4c00 /src/BlockState.cpp | |
parent | Added missing closing } in message output (diff) | |
download | cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.gz cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.bz2 cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.lz cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.xz cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.zst cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.zip |
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: |