util/IntrusiveHashSet: add concept checks to *Operators
This requires adding another template argument and reordering the others.
This commit is contained in:
parent
91ca502e10
commit
6a99f20828
|
@ -85,9 +85,9 @@ class RemoteTagCache final {
|
||||||
|
|
||||||
IntrusiveHashSet<
|
IntrusiveHashSet<
|
||||||
Item, 127,
|
Item, 127,
|
||||||
IntrusiveHashSetOperators<std::hash<std::string_view>,
|
IntrusiveHashSetOperators<Item, Item::GetUri,
|
||||||
std::equal_to<std::string_view>,
|
std::hash<std::string_view>,
|
||||||
Item::GetUri>,
|
std::equal_to<std::string_view>>,
|
||||||
IntrusiveHashSetBaseHookTraits<Item>,
|
IntrusiveHashSetBaseHookTraits<Item>,
|
||||||
IntrusiveHashSetOptions{.constant_time_size = true}> map;
|
IntrusiveHashSetOptions{.constant_time_size = true}> map;
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,9 @@ class InputCacheManager {
|
||||||
IntrusiveList<InputCacheItem> items_by_time;
|
IntrusiveList<InputCacheItem> items_by_time;
|
||||||
|
|
||||||
IntrusiveHashSet<InputCacheItem, 127,
|
IntrusiveHashSet<InputCacheItem, 127,
|
||||||
IntrusiveHashSetOperators<std::hash<std::string_view>,
|
IntrusiveHashSetOperators<InputCacheItem, ItemGetUri,
|
||||||
std::equal_to<std::string_view>,
|
std::hash<std::string_view>,
|
||||||
ItemGetUri>> items_by_uri;
|
std::equal_to<std::string_view>>> items_by_uri;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit InputCacheManager(const InputCacheConfig &config) noexcept;
|
explicit InputCacheManager(const InputCacheConfig &config) noexcept;
|
||||||
|
|
|
@ -78,9 +78,9 @@ TagPoolItem::Create(TagType type,
|
||||||
}
|
}
|
||||||
|
|
||||||
static IntrusiveHashSet<TagPoolItem, 16384,
|
static IntrusiveHashSet<TagPoolItem, 16384,
|
||||||
IntrusiveHashSetOperators<TagPoolKey::Hash,
|
IntrusiveHashSetOperators<TagPoolItem, TagPoolItem::GetKey,
|
||||||
std::equal_to<TagPoolKey>,
|
TagPoolKey::Hash,
|
||||||
TagPoolItem::GetKey>,
|
std::equal_to<TagPoolKey>>,
|
||||||
IntrusiveHashSetMemberHookTraits<&TagPoolItem::hash_set_hook>,
|
IntrusiveHashSetMemberHookTraits<&TagPoolItem::hash_set_hook>,
|
||||||
IntrusiveHashSetOptions{.zero_initialized = true}> tag_pool;
|
IntrusiveHashSetOptions{.zero_initialized = true}> tag_pool;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <algorithm> // for std::all_of()
|
#include <algorithm> // for std::all_of()
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <concepts> // for std::regular_invocable
|
||||||
#include <numeric> // for std::accumulate()
|
#include <numeric> // for std::accumulate()
|
||||||
|
|
||||||
struct IntrusiveHashSetOptions {
|
struct IntrusiveHashSetOptions {
|
||||||
|
@ -94,8 +95,11 @@ struct IntrusiveHashSetMemberHookTraits {
|
||||||
* @param GetKey a function object which extracts the "key" part of an
|
* @param GetKey a function object which extracts the "key" part of an
|
||||||
* item
|
* item
|
||||||
*/
|
*/
|
||||||
template<typename Hash, typename Equal,
|
template<typename T,
|
||||||
typename GetKey=std::identity>
|
std::regular_invocable<const T &> GetKey,
|
||||||
|
std::regular_invocable<std::invoke_result_t<GetKey, const T &>> Hash,
|
||||||
|
std::predicate<std::invoke_result_t<GetKey, const T &>,
|
||||||
|
std::invoke_result_t<GetKey, const T &>> Equal>
|
||||||
struct IntrusiveHashSetOperators {
|
struct IntrusiveHashSetOperators {
|
||||||
using hasher = Hash;
|
using hasher = Hash;
|
||||||
using key_equal = Equal;
|
using key_equal = Equal;
|
||||||
|
|
|
@ -39,7 +39,8 @@ TEST(IntrusiveHashSet, Basic)
|
||||||
IntItem a{1}, b{2}, c{3}, d{4}, e{5}, f{1};
|
IntItem a{1}, b{2}, c{3}, d{4}, e{5}, f{1};
|
||||||
|
|
||||||
IntrusiveHashSet<IntItem, 3,
|
IntrusiveHashSet<IntItem, 3,
|
||||||
IntrusiveHashSetOperators<IntItem::Hash,
|
IntrusiveHashSetOperators<IntItem, std::identity,
|
||||||
|
IntItem::Hash,
|
||||||
IntItem::Equal>> set;
|
IntItem::Equal>> set;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -124,7 +125,8 @@ TEST(IntrusiveHashSet, Multi)
|
||||||
IntItem a{1}, b{2}, c{3}, d{4}, e{5}, f{1};
|
IntItem a{1}, b{2}, c{3}, d{4}, e{5}, f{1};
|
||||||
|
|
||||||
IntrusiveHashSet<IntItem, 3,
|
IntrusiveHashSet<IntItem, 3,
|
||||||
IntrusiveHashSetOperators<IntItem::Hash,
|
IntrusiveHashSetOperators<IntItem, std::identity,
|
||||||
|
IntItem::Hash,
|
||||||
IntItem::Equal>> set;
|
IntItem::Equal>> set;
|
||||||
|
|
||||||
set.insert(a);
|
set.insert(a);
|
||||||
|
@ -179,15 +181,15 @@ TEST(IntrusiveHashSet, Tag)
|
||||||
TaggedItem one{1, 11}, two{2, 22};
|
TaggedItem one{1, 11}, two{2, 22};
|
||||||
|
|
||||||
IntrusiveHashSet<TaggedItem, 3,
|
IntrusiveHashSet<TaggedItem, 3,
|
||||||
IntrusiveHashSetOperators<std::hash<int>,
|
IntrusiveHashSetOperators<TaggedItem, GetA,
|
||||||
std::equal_to<int>,
|
std::hash<int>,
|
||||||
GetA>,
|
std::equal_to<int>>,
|
||||||
IntrusiveHashSetBaseHookTraits<TaggedItem, A>> a;
|
IntrusiveHashSetBaseHookTraits<TaggedItem, A>> a;
|
||||||
|
|
||||||
IntrusiveHashSet<TaggedItem, 3,
|
IntrusiveHashSet<TaggedItem, 3,
|
||||||
IntrusiveHashSetOperators<std::hash<int>,
|
IntrusiveHashSetOperators<TaggedItem, GetB,
|
||||||
std::equal_to<int>,
|
std::hash<int>,
|
||||||
GetB>,
|
std::equal_to<int>>,
|
||||||
IntrusiveHashSetBaseHookTraits<TaggedItem, B>> b;
|
IntrusiveHashSetBaseHookTraits<TaggedItem, B>> b;
|
||||||
|
|
||||||
EXPECT_TRUE(a.empty());
|
EXPECT_TRUE(a.empty());
|
||||||
|
|
Loading…
Reference in New Issue