Pass equality comparator to is_hash_table_key_empty.

This commit is contained in:
levlam 2024-03-21 18:43:47 +03:00
parent 1d6e7afcdf
commit 0c3da400d9
8 changed files with 21 additions and 21 deletions

View File

@ -17,7 +17,7 @@
namespace td {
template <class KeyT, class ValueT, class HashT = Hash<KeyT>, class EqT = std::equal_to<KeyT>>
using FlatHashMap = FlatHashTable<MapNode<KeyT, ValueT>, HashT, EqT>;
using FlatHashMap = FlatHashTable<MapNode<KeyT, ValueT, EqT>, HashT, EqT>;
//using FlatHashMap = FlatHashMapChunks<KeyT, ValueT, HashT, EqT>;
//using FlatHashMap = std::unordered_map<KeyT, ValueT, HashT, EqT>;

View File

@ -257,7 +257,7 @@ class FlatHashTableChunks {
}
Iterator find(const KeyT &key) {
if (empty() || is_hash_table_key_empty(key)) {
if (empty() || is_hash_table_key_empty<EqT>(key)) {
return end();
}
const auto hash = calc_hash(key);
@ -326,7 +326,7 @@ class FlatHashTableChunks {
template <class... ArgsT>
std::pair<Iterator, bool> emplace(KeyT key, ArgsT &&...args) {
CHECK(!is_hash_table_key_empty(key));
CHECK(!is_hash_table_key_empty<EqT>(key));
auto it = find(key);
if (it != end()) {
return {it, false};
@ -562,10 +562,10 @@ class FlatHashTableChunks {
};
template <class KeyT, class ValueT, class HashT = Hash<KeyT>, class EqT = std::equal_to<KeyT>>
using FlatHashMapChunks = FlatHashTableChunks<MapNode<KeyT, ValueT>, HashT, EqT>;
using FlatHashMapChunks = FlatHashTableChunks<MapNode<KeyT, ValueT, EqT>, HashT, EqT>;
template <class KeyT, class HashT = Hash<KeyT>, class EqT = std::equal_to<KeyT>>
using FlatHashSetChunks = FlatHashTableChunks<SetNode<KeyT>, HashT, EqT>;
using FlatHashSetChunks = FlatHashTableChunks<SetNode<KeyT, EqT>, HashT, EqT>;
template <class NodeT, class HashT, class EqT, class FuncT>
void table_remove_if(FlatHashTableChunks<NodeT, HashT, EqT> &table, FuncT &&func) {

View File

@ -17,7 +17,7 @@
namespace td {
template <class KeyT, class HashT = Hash<KeyT>, class EqT = std::equal_to<KeyT>>
using FlatHashSet = FlatHashTable<SetNode<KeyT>, HashT, EqT>;
using FlatHashSet = FlatHashTable<SetNode<KeyT, EqT>, HashT, EqT>;
//using FlatHashSet = FlatHashSetChunks<KeyT, HashT, EqT>;
//using FlatHashSet = std::unordered_set<KeyT, HashT, EqT>;

View File

@ -308,7 +308,7 @@ class FlatHashTable {
template <class... ArgsT>
std::pair<NodePointer, bool> emplace(KeyT key, ArgsT &&...args) {
CHECK(!is_hash_table_key_empty(key));
CHECK(!is_hash_table_key_empty<EqT>(key));
if (unlikely(bucket_count_mask_ == 0)) {
CHECK(used_node_count_ == 0);
resize(8);
@ -447,7 +447,7 @@ class FlatHashTable {
}
NodeT *find_impl(const KeyT &key) {
if (unlikely(nodes_ == nullptr) || is_hash_table_key_empty(key)) {
if (unlikely(nodes_ == nullptr) || is_hash_table_key_empty<EqT>(key)) {
return nullptr;
}
auto bucket = calc_bucket(key);

View File

@ -13,9 +13,9 @@
namespace td {
template <class KeyT>
template <class EqT, class KeyT>
bool is_hash_table_key_empty(const KeyT &key) {
return key == KeyT();
return EqT()(key, KeyT());
}
inline uint32 randomize_hash(uint32 h) {

View File

@ -15,7 +15,7 @@
namespace td {
template <class KeyT, class ValueT, class Enable = void>
template <class KeyT, class ValueT, class EqT, class Enable = void>
struct MapNode {
using first_type = KeyT;
using second_type = ValueT;
@ -72,7 +72,7 @@ struct MapNode {
}
bool empty() const {
return is_hash_table_key_empty(first);
return is_hash_table_key_empty<EqT>(first);
}
void clear() {
@ -91,8 +91,8 @@ struct MapNode {
}
};
template <class KeyT, class ValueT>
struct MapNode<KeyT, ValueT, typename std::enable_if_t<(sizeof(KeyT) + sizeof(ValueT) > 28 * sizeof(void *))>> {
template <class KeyT, class ValueT, class EqT>
struct MapNode<KeyT, ValueT, EqT, typename std::enable_if_t<(sizeof(KeyT) + sizeof(ValueT) > 28 * sizeof(void *))>> {
struct Impl {
using first_type = KeyT;
using second_type = ValueT;
@ -105,7 +105,7 @@ struct MapNode<KeyT, ValueT, typename std::enable_if_t<(sizeof(KeyT) + sizeof(Va
template <class InputKeyT, class... ArgsT>
Impl(InputKeyT &&key, ArgsT &&...args) : first(std::forward<InputKeyT>(key)) {
new (&second) ValueT(std::forward<ArgsT>(args)...);
DCHECK(!is_hash_table_key_empty(first));
DCHECK(!is_hash_table_key_empty<EqT>(first));
}
Impl(const Impl &) = delete;
Impl &operator=(const Impl &) = delete;

View File

@ -14,7 +14,7 @@
namespace td {
template <class KeyT, class Enable = void>
template <class KeyT, class EqT, class Enable = void>
struct SetNode {
using public_key_type = KeyT;
using public_type = const KeyT;
@ -54,7 +54,7 @@ struct SetNode {
}
bool empty() const {
return is_hash_table_key_empty(first);
return is_hash_table_key_empty<EqT>(first);
}
void clear() {
@ -67,8 +67,8 @@ struct SetNode {
}
};
template <class KeyT>
struct SetNode<KeyT, typename std::enable_if_t<(sizeof(KeyT) > 28 * sizeof(void *))>> {
template <class KeyT, class EqT>
struct SetNode<KeyT, EqT, typename std::enable_if_t<(sizeof(KeyT) > 28 * sizeof(void *))>> {
struct Impl {
using second_type = KeyT;
@ -76,7 +76,7 @@ struct SetNode<KeyT, typename std::enable_if_t<(sizeof(KeyT) > 28 * sizeof(void
template <class InputKeyT>
explicit Impl(InputKeyT &&key) : first(std::forward<InputKeyT>(key)) {
DCHECK(!is_hash_table_key_empty(first));
DCHECK(!is_hash_table_key_empty<EqT>(first));
}
Impl(const Impl &) = delete;
Impl &operator=(const Impl &) = delete;

View File

@ -590,7 +590,7 @@ BENCHMARK_TEMPLATE(BM_mask, td::MaskSse2);
#endif
template <class KeyT, class ValueT, class HashT = td::Hash<KeyT>, class EqT = std::equal_to<KeyT>>
using FlatHashMapImpl = td::FlatHashTable<td::MapNode<KeyT, ValueT>, HashT, EqT>;
using FlatHashMapImpl = td::FlatHashTable<td::MapNode<KeyT, ValueT, EqT>, HashT, EqT>;
#define FOR_EACH_TABLE(F) \
F(FlatHashMapImpl) \