mirror of
https://github.com/ceph/ceph
synced 2025-03-05 07:48:55 +00:00
object.h: hobject_t definition
Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
This commit is contained in:
parent
de1f424a72
commit
45d829646d
@ -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<sobject_t> {
|
||||
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<sobject_t>()(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<hobject_t> {
|
||||
size_t operator()(const sobject_t &r) const {
|
||||
static hash<object_t> H;
|
||||
static rjhash<uint64_t> I;
|
||||
return H(r.oid) ^ I(r.snap);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user