From 348321a591d3b0db2a4770d165a3bb82b0264a60 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 1 Dec 2011 20:57:09 -0800 Subject: [PATCH] hobject_t: sort by (max, hash, oid, snap) Signed-off-by: Sage Weil --- src/include/object.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/include/object.h b/src/include/object.h index 4b044d6db1b3b..c7884711e6e26 100644 --- a/src/include/object.h +++ b/src/include/object.h @@ -330,6 +330,7 @@ public: } }; WRITE_CLASS_ENCODER(hobject_t) + namespace __gnu_cxx { template<> struct hash { size_t operator()(const sobject_t &r) const { @@ -340,6 +341,39 @@ namespace __gnu_cxx { }; } +// sort hobject_t's by +inline bool operator==(const hobject_t &l, const hobject_t &r) { + return l.oid == r.oid && l.snap == r.snap && l.hash == r.hash && l.max == r.max; +} +inline bool operator!=(const hobject_t &l, const hobject_t &r) { + return l.oid != r.oid || l.snap != r.snap || l.hash != r.hash || l.max != r.max; +} +inline bool operator>(const hobject_t &l, const hobject_t &r) { + return l.max > r.max || + (l.max == r.max && (l.hash > r.hash || + (l.hash == r.hash && (l.oid > r.oid || + (l.oid == r.oid && l.snap > r.snap))))); +} +inline bool operator<(const hobject_t &l, const hobject_t &r) { + return l.max < r.max || + (l.max == r.max && (l.hash < r.hash || + (l.hash == r.hash && (l.oid < r.oid || + (l.oid == r.oid && l.snap < r.snap))))); +} +inline bool operator>=(const hobject_t &l, const hobject_t &r) { + return l.max > r.max || + (l.max == r.max && (l.hash > r.hash || + (l.hash == r.hash && (l.oid > r.oid || + (l.oid == r.oid && l.snap >= r.snap))))); +} +inline bool operator<=(const hobject_t &l, const hobject_t &r) { + return l.max < r.max || + (l.max == r.max && (l.hash < r.hash || + (l.hash == r.hash && (l.oid < r.oid || + (l.oid == r.oid && l.snap <= r.snap))))); +} + + // --------------------------- #endif -- 2.39.5