Skip to content

Commit

Permalink
util/StringWithHash: add std::hash specialization
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 22, 2025
1 parent d76d995 commit 99a6270
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
16 changes: 2 additions & 14 deletions src/stock/MapStock.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ class StockMap {
void OnDeferredEmpty() noexcept;

public:
struct Hash {
constexpr size_t operator()(const StockKey &key) const noexcept {
return key.hash;
}
};

struct Equal {
constexpr bool operator()(const StockKey &a, const StockKey &b) const noexcept {
return a == b;
}
};

struct GetKeyFunction {
[[gnu::pure]]
StockKey operator()(const Item &item) const noexcept {
Expand All @@ -65,8 +53,8 @@ class StockMap {
IntrusiveHashSet<Item, N_BUCKETS,
IntrusiveHashSetOperators<Item,
Item::GetKeyFunction,
Item::Hash,
Item::Equal>>;
std::hash<StockKey>,
std::equal_to<StockKey>>>;

EventLoop &event_loop;

Expand Down
16 changes: 2 additions & 14 deletions src/stock/MultiStock.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,6 @@ class MultiStock {
std::exception_ptr ep) noexcept override;

public:
struct Hash {
constexpr size_t operator()(const StockKey &key) const noexcept {
return key.hash;
}
};

struct Equal {
constexpr bool operator()(const StockKey &a, const StockKey &b) const noexcept {
return a == b;
}
};

struct GetKey {
[[gnu::pure]]
StockKey operator()(const MapItem &item) const noexcept {
Expand All @@ -342,8 +330,8 @@ class MultiStock {
using Map =
IntrusiveHashSet<MapItem, N_BUCKETS,
IntrusiveHashSetOperators<MapItem, MapItem::GetKey,
MapItem::Hash,
MapItem::Equal>>;
std::hash<StockKey>,
std::equal_to<StockKey>>>;

Map map;

Expand Down
7 changes: 7 additions & 0 deletions src/util/StringWithHash.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ struct StringWithHash {

constexpr bool operator==(const StringWithHash &) const noexcept = default;
};

template<>
struct std::hash<StringWithHash> {
constexpr std::size_t operator()(const StringWithHash &s) const noexcept {
return s.hash;
}
};

0 comments on commit 99a6270

Please sign in to comment.