mirror of
https://github.com/ceph/ceph
synced 2025-01-11 13:41:02 +00:00
07ac5d3e74
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1068 29311d96-e01e-0410-9327-a35deaab8ce9
92 lines
2.4 KiB
C++
92 lines
2.4 KiB
C++
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
|
/*
|
|
* Ceph - scalable distributed file system
|
|
*
|
|
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
|
|
*
|
|
* This is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License version 2.1, as published by the Free Software
|
|
* Foundation. See file COPYING.
|
|
*
|
|
*/
|
|
|
|
#ifndef __OBJECT_H
|
|
#define __OBJECT_H
|
|
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
using namespace std;
|
|
|
|
|
|
typedef __uint32_t objectrev_t;
|
|
|
|
struct object_t {
|
|
static const __uint32_t MAXREV = 0xffffffffU;
|
|
|
|
__uint64_t ino; // "file" identifier
|
|
__uint32_t bno; // "block" in that "file"
|
|
objectrev_t rev; // revision. normally ctime (as epoch).
|
|
|
|
object_t() : ino(0), bno(0), rev(0) {}
|
|
object_t(__uint64_t i, __uint32_t b) : ino(i), bno(b), rev(0) {}
|
|
};
|
|
|
|
|
|
inline bool operator==(const object_t l, const object_t r) {
|
|
return (l.ino == r.ino) && (l.bno == r.bno) && (l.rev == r.rev);
|
|
}
|
|
inline bool operator!=(const object_t l, const object_t r) {
|
|
return (l.ino != r.ino) || (l.bno != r.bno) || (l.rev != r.rev);
|
|
}
|
|
inline bool operator>(const object_t l, const object_t r) {
|
|
if (l.ino > r.ino) return true;
|
|
if (l.ino < r.ino) return false;
|
|
if (l.bno > r.bno) return true;
|
|
if (l.bno < r.bno) return false;
|
|
if (l.rev > r.rev) return true;
|
|
return false;
|
|
}
|
|
inline bool operator<(const object_t l, const object_t r) {
|
|
if (l.ino < r.ino) return true;
|
|
if (l.ino > r.ino) return false;
|
|
if (l.bno < r.bno) return true;
|
|
if (l.bno > r.bno) return false;
|
|
if (l.rev < r.rev) return true;
|
|
return false;
|
|
}
|
|
inline bool operator>=(const object_t l, const object_t r) {
|
|
return !(l < r);
|
|
}
|
|
inline bool operator<=(const object_t l, const object_t r) {
|
|
return !(l > r);
|
|
}
|
|
inline ostream& operator<<(ostream& out, const object_t o) {
|
|
out << hex << o.ino << '.';
|
|
out.setf(ios::right);
|
|
out.fill('0');
|
|
out << setw(8) << o.bno << dec;
|
|
out.unsetf(ios::right);
|
|
if (o.rev)
|
|
out << '.' << o.rev;
|
|
return out;
|
|
}
|
|
namespace __gnu_cxx {
|
|
template<> struct hash<__uint64_t> {
|
|
size_t operator()(__uint64_t __x) const {
|
|
static hash<__uint32_t> H;
|
|
return H((__x >> 32) ^ (__x & 0xffffffff));
|
|
}
|
|
};
|
|
|
|
template<> struct hash<object_t> {
|
|
size_t operator()(const object_t &r) const {
|
|
static hash<__uint64_t> H;
|
|
static hash<__uint32_t> I;
|
|
return H(r.ino) ^ I(r.bno);
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif
|