object.h: Sort hobject_t by nibble reversed hash

To match the HashIndex ordering, we need to sort hobject_t by the nibble
reversed hash.  We store objects in the filestore in a directory tree
with the least significant nibble at the top and the most at the bottom
to facilitate pg splitting in the future.

Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
This commit is contained in:
Samuel Just 2011-11-30 10:38:09 -08:00
parent 348321a591
commit cada2f2ef4

View File

@ -259,6 +259,7 @@ namespace __gnu_cxx {
};
}
typedef uint32_t filestore_hobject_key_t;
struct hobject_t {
object_t oid;
snapid_t snap;
@ -289,6 +290,15 @@ public:
return h;
}
filestore_hobject_key_t get_filestore_key() const {
uint32_t retval = hash;
// reverse nibbles
retval = ((retval & 0x0f0f0f0f) << 4) | ((retval & 0xf0f0f0f0) >> 4);
retval = ((retval & 0x00ff00ff) << 8) | ((retval & 0xff00ff00) >> 8);
retval = ((retval & 0x0000ffff) << 16) | ((retval & 0xffff0000) >> 16);
return retval;
}
/* Do not use when a particular hash function is needed */
explicit hobject_t(const sobject_t &o) :
oid(o.oid), snap(o.snap) {
@ -341,7 +351,7 @@ namespace __gnu_cxx {
};
}
// sort hobject_t's by <hash,name,snapid>
// sort hobject_t's by <get_filestore_key,name,snapid>
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;
}
@ -350,26 +360,26 @@ inline bool operator!=(const hobject_t &l, const hobject_t &r) {
}
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.max == r.max && (l.get_filestore_key() > r.get_filestore_key() ||
(l.get_filestore_key() == r.get_filestore_key() && (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.max == r.max && (l.get_filestore_key() < r.get_filestore_key() ||
(l.get_filestore_key() == r.get_filestore_key() && (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.max == r.max && (l.get_filestore_key() > r.get_filestore_key() ||
(l.get_filestore_key() == r.get_filestore_key() && (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.max == r.max && (l.get_filestore_key() < r.get_filestore_key() ||
(l.get_filestore_key() == r.get_filestore_key() && (l.oid < r.oid ||
(l.oid == r.oid && l.snap <= r.snap)))));
}