2014-12-09 20:36:32 +01:00
|
|
|
#pragma once
|
2015-10-15 13:09:21 +02:00
|
|
|
#ifndef MESSMER_BLOCKSTORE_UTILS_KEY_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_UTILS_KEY_H_
|
2014-12-09 20:36:32 +01:00
|
|
|
|
|
|
|
#include <string>
|
2015-04-25 02:48:41 +02:00
|
|
|
#include <messmer/cpp-utils/data/FixedSizeData.h>
|
2014-12-09 20:36:32 +01:00
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
|
2015-10-22 17:41:43 +02:00
|
|
|
// A key here is NOT a key for encryption, but a key as used in key->value mappings ("access handle for a block").
|
|
|
|
//TODO Rename to BlockId/BlobId and make it a class containing a FixedSizeData<> member
|
|
|
|
using Key = cpputils::FixedSizeData<16>;
|
2014-12-09 20:36:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-17 12:56:21 +02:00
|
|
|
namespace std {
|
|
|
|
//Allow using blockstore::Key in std::unordered_map / std::unordered_set
|
|
|
|
template <> struct hash<blockstore::Key> {
|
|
|
|
size_t operator()(const blockstore::Key &key) const {
|
|
|
|
//Keys are random, so it is enough to use the first few bytes as a hash
|
|
|
|
return *(size_t*)(key.data());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//Allow using blockstore::Key in std::map / std::set
|
|
|
|
template <> struct less<blockstore::Key> {
|
|
|
|
bool operator()(const blockstore::Key &lhs, const blockstore::Key &rhs) const {
|
|
|
|
return 0 > std::memcmp(lhs.data(), rhs.data(), blockstore::Key::BINARY_LENGTH);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-12-09 20:36:32 +01:00
|
|
|
#endif
|