-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BlobRoute : Comparison and Hash can be made much cheaper without stri…
…ng formatting. (#66) * Comparison and Hash can be made much cheaper without string formatting. * Remove magic numbers * Lift shard_mask * Uplift make_new_shard_id * Use boost::hash_value
- Loading branch information
Showing
6 changed files
with
55 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <functional> | ||
|
||
#include <boost/functional/hash.hpp> | ||
|
||
#include "homeobject/common.hpp" | ||
|
||
namespace homeobject { | ||
|
||
/// | ||
// A Key used in the IndexService (BTree). The inclusion of Shard allows BlobRoutes | ||
// to appear in a different Index should the Blob (Shard) be moved between Pgs. | ||
struct BlobRoute { | ||
shard_id shard; | ||
blob_id blob; | ||
auto operator<=>(BlobRoute const&) const = default; | ||
}; | ||
|
||
} // namespace homeobject | ||
|
||
namespace fmt { | ||
template <> | ||
struct formatter< homeobject::BlobRoute > { | ||
template < typename ParseContext > | ||
constexpr auto parse(ParseContext& ctx) { | ||
return ctx.begin(); | ||
} | ||
|
||
template < typename FormatContext > | ||
auto format(homeobject::BlobRoute const& r, FormatContext& ctx) { | ||
return format_to(ctx.out(), "{:04x}:{:012x}:{:016x}", (r.shard >> homeobject::shard_width), | ||
(r.shard & homeobject::shard_mask), r.blob); | ||
} | ||
}; | ||
} // namespace fmt | ||
|
||
template <> | ||
struct std::hash< homeobject::BlobRoute > { | ||
std::size_t operator()(homeobject::BlobRoute const& r) const noexcept { | ||
return boost::hash_value< homeobject::blob_id >(std::make_pair(r.shard, r.blob)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters