2014-12-09 20:36:32 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef BLOCKSTORE_UTILS_KEY_H_
|
|
|
|
#define BLOCKSTORE_UTILS_KEY_H_
|
|
|
|
|
|
|
|
#include <string>
|
2015-04-09 20:07:03 +02:00
|
|
|
#include "FixedSizeData.h"
|
2014-12-09 20:36:32 +01:00
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
|
|
|
|
// A key here is NOT a key for encryption, but a key as used in key->value mappings ("access handle for a block").
|
2015-04-09 20:07:03 +02:00
|
|
|
using Key = FixedSizeData<16>;
|
2015-03-28 18:44:22 +01:00
|
|
|
|
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
|