From 45d829646ddb7fdcd21b5ff1a4620ee098f9b79a Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Fri, 8 Jul 2011 10:45:34 -0700 Subject: [PATCH] object.h: hobject_t definition Signed-off-by: Samuel Just --- src/include/object.h | 58 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/include/object.h b/src/include/object.h index 5e41454dd328d..bc56445fd1e29 100644 --- a/src/include/object.h +++ b/src/include/object.h @@ -249,7 +249,6 @@ inline bool operator<=(const sobject_t &l, const sobject_t &r) { inline ostream& operator<<(ostream& out, const sobject_t &o) { return out << o.oid << "/" << o.snap; } - namespace __gnu_cxx { template<> struct hash { size_t operator()(const sobject_t &r) const { @@ -260,6 +259,63 @@ namespace __gnu_cxx { }; } +struct hobject_t { + object_t oid; + snapid_t snap; + uint32_t hash; + + hobject_t() : snap(0), hash(0) {} + hobject_t(object_t oid, snapid_t snap, uint32_t hash) : + oid(oid), snap(snap), hash(hash) {} + hobject_t(const sobject_t &soid, uint32_t hash) : + oid(soid.oid), snap(soid.snap), hash(hash) {} + + /* Do not use when a particular hash function is needed */ + explicit hobject_t(const sobject_t &o) : + oid(o.oid), snap(o.snap) { + hash = __gnu_cxx::hash()(o); + } + + void swap(hobject_t &o) { + hobject_t temp(o); + o.oid = oid; + o.snap = snap; + o.hash = hash; + oid = temp.oid; + snap = temp.snap; + hash = temp.hash; + } + + operator sobject_t() const { + return sobject_t(oid, snap); + } + + void encode(bufferlist& bl) const { + __u8 version = 0; + ::encode(version, bl); + ::encode(oid, bl); + ::encode(snap, bl); + ::encode(hash, bl); + } + void decode(bufferlist::iterator& bl) { + __u8 version; + ::decode(version, bl); + ::decode(oid, bl); + ::decode(snap, bl); + ::decode(hash, bl); + } +}; +WRITE_CLASS_ENCODER(hobject_t) +namespace __gnu_cxx { + template<> struct hash { + size_t operator()(const sobject_t &r) const { + static hash H; + static rjhash I; + return H(r.oid) ^ I(r.snap); + } + }; +} + // --------------------------- #endif -- 2.39.5