271
278
const string &get_key() const {
282
hobject_t() : snap(0), hash(0), max(false) {}
275
hobject_t() : snap(0), hash(0) {}
276
hobject_t(object_t oid, const string &key, snapid_t snap, uint32_t hash) :
277
oid(oid), snap(snap), hash(hash),
284
hobject_t(object_t oid, const string& key, snapid_t snap, uint64_t hash) :
285
oid(oid), snap(snap), hash(hash), max(false),
278
286
key(oid.name == key ? string() : key) {}
280
288
hobject_t(const sobject_t &soid, const string &key, uint32_t hash) :
281
oid(soid.oid), snap(soid.snap), hash(hash),
289
oid(soid.oid), snap(soid.snap), hash(hash), max(false),
282
290
key(soid.oid.name == key ? string() : key) {}
284
292
/* Do not use when a particular hash function is needed */
285
293
explicit hobject_t(const sobject_t &o) :
286
oid(o.oid), snap(o.snap) {
294
oid(o.oid), snap(o.snap), max(false) {
287
295
hash = __gnu_cxx::hash<sobject_t>()(o);
298
// maximum sorted value.
299
static hobject_t get_max() {
304
bool is_max() const {
308
static uint32_t _reverse_nibbles(uint32_t retval) {
310
retval = ((retval & 0x0f0f0f0f) << 4) | ((retval & 0xf0f0f0f0) >> 4);
311
retval = ((retval & 0x00ff00ff) << 8) | ((retval & 0xff00ff00) >> 8);
312
retval = ((retval & 0x0000ffff) << 16) | ((retval & 0xffff0000) >> 16);
316
filestore_hobject_key_t get_filestore_key() const {
318
return 0x100000000ull;
320
return _reverse_nibbles(hash);
322
void set_filestore_key(uint32_t v) {
323
hash = _reverse_nibbles(v);
326
const string& get_effective_key() const {
333
* back up hobject_t to beginning of hash bucket, if i am partway through one.
335
void back_up_to_bounding_key() {
290
345
void swap(hobject_t &o) {
291
346
hobject_t temp(o);
319
371
::decode(oid, bl);
320
372
::decode(snap, bl);
321
373
::decode(hash, bl);
324
380
WRITE_CLASS_ENCODER(hobject_t)
325
382
namespace __gnu_cxx {
326
383
template<> struct hash<hobject_t> {
327
size_t operator()(const sobject_t &r) const {
384
size_t operator()(const hobject_t &r) const {
328
385
static hash<object_t> H;
329
386
static rjhash<uint64_t> I;
330
387
return H(r.oid) ^ I(r.snap);
392
inline ostream& operator<<(ostream& out, const hobject_t& o)
396
out << std::hex << o.hash << std::dec;
397
if (o.get_key().length())
398
out << "." << o.get_key();
399
out << "/" << o.oid << "/" << o.snap;
403
WRITE_EQ_OPERATORS_5(hobject_t, oid, get_key(), snap, hash, max)
404
// sort hobject_t's by <max, get_filestore_key(hash), key, oid, snapid>
405
WRITE_CMP_OPERATORS_5(hobject_t, max, get_filestore_key(), get_effective_key(), oid, snap)
335
408
// ---------------------------