# # # patch "rev_height.cc" # from [7c820572e5b5b9b67f6fcfee194838fa6b1e787c] # to [f44979ce3c7ba571c00cf0c810991aec9f7f84fa] # # patch "rev_height.hh" # from [cd31dbcb051c6a2181c971654f34ededb32a70c5] # to [448eee2ee56b8ba3f25e3116ed624b258fd0ed89] # ============================================================ --- rev_height.cc 7c820572e5b5b9b67f6fcfee194838fa6b1e787c +++ rev_height.cc f44979ce3c7ba571c00cf0c810991aec9f7f84fa @@ -7,7 +7,6 @@ // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. -#include #include #include "sanity.hh" @@ -16,7 +15,6 @@ using std::ostringstream; using std::ostream; using std::string; using std::ostringstream; -using std::memcmp; /* * Implementation note: hv, holding the raw revision height, is @@ -32,26 +30,6 @@ using std::memcmp; * */ -// Comparisons -bool rev_height::operator==(rev_height const & other) const -{ - if (d.size() != other.d.size()) - return false; - - // sizes are equal - return (memcmp(d.data(), other.d.data(), d.size()) == 0); -} - -bool rev_height::operator<(rev_height const & other) const -{ - int o = memcmp(d.data(), other.d.data(), - std::min(d.size(), other.d.size())); - if (o != 0) - return o < 0; - else - return d.size() < other.d.size(); -} - // Internal manipulations size_t const width = sizeof(u32); @@ -218,6 +196,24 @@ UNIT_TEST(rev_height, children) } } +UNIT_TEST(rev_height, comparisons) +{ + rev_height root(rev_height::root_height()); + rev_height left(root.child_height(0)); + rev_height right(root.child_height(1)); + + I(root < left); + I(root < right); + I(right < left); + for (u32 i = 0; i < 1000; i++) + { + rev_height rchild(right.child_height(0)); + I(right < rchild); + I(rchild < left); + right = rchild; + } +} + #endif // Local Variables: ============================================================ --- rev_height.hh cd31dbcb051c6a2181c971654f34ededb32a70c5 +++ rev_height.hh 448eee2ee56b8ba3f25e3116ed624b258fd0ed89 @@ -29,24 +29,29 @@ public: bool valid() const { return d.size() > 0; } - bool operator ==(rev_height const & other) const; - bool operator < (rev_height const & other) const; - + bool operator ==(rev_height const & other) const + { + return this->d == other.d; + } + bool operator < (rev_height const & other) const + { + return this->d < other.d; + } bool operator !=(rev_height const & other) const { - return !(*this == other); + return this->d != other.d; } bool operator > (rev_height const & other) const { - return other < *this; + return this->d > other.d; } bool operator <=(rev_height const & other) const { - return !(other < *this); + return this->d <= other.d; } bool operator >=(rev_height const & other) const { - return !(*this < other); + return this->d >= other.d; } };