Keep the first value from initializer_list.

This commit is contained in:
levlam 2022-02-21 00:33:19 +03:00
parent 77ccc13181
commit 9e8b2489bd
5 changed files with 9 additions and 14 deletions

View File

@ -14,13 +14,13 @@
namespace td { namespace td {
template <class KeyT, class ValueT, class HashT = std::hash<KeyT>, class EqT = std::equal_to<KeyT>> template <class KeyT, class ValueT, class HashT = std::hash<KeyT>, class EqT = std::equal_to<KeyT>>
using FlatHashMap = FlatHashMapImpl<KeyT, ValueT, HashT, EqT>; //using FlatHashMap = FlatHashMapImpl<KeyT, ValueT, HashT, EqT>;
//using FlatHashMap = FlatHashMapChunks<KeyT, ValueT, HashT, EqT>; using FlatHashMap = FlatHashMapChunks<KeyT, ValueT, HashT, EqT>;
//using FlatHashMap = std::unordered_map<KeyT, ValueT, HashT, EqT>; //using FlatHashMap = std::unordered_map<KeyT, ValueT, HashT, EqT>;
template <class KeyT, class HashT = std::hash<KeyT>, class EqT = std::equal_to<KeyT>> template <class KeyT, class HashT = std::hash<KeyT>, class EqT = std::equal_to<KeyT>>
using FlatHashSet = FlatHashSetImpl<KeyT, HashT, EqT>; //using FlatHashSet = FlatHashSetImpl<KeyT, HashT, EqT>;
//using FlatHashSet = FlatHashSetChunks<KeyT, HashT, EqT>; using FlatHashSet = FlatHashSetChunks<KeyT, HashT, EqT>;
//using FlatHashSet = std::unordered_set<KeyT, HashT, EqT>; //using FlatHashSet = std::unordered_set<KeyT, HashT, EqT>;
} // namespace td } // namespace td

View File

@ -6,7 +6,6 @@
// //
#pragma once #pragma once
#include "td/utils/algorithm.h"
#include "td/utils/bits.h" #include "td/utils/bits.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/FlatHashMapLinear.h" #include "td/utils/FlatHashMapLinear.h"
@ -224,9 +223,9 @@ class FlatHashTableChunks {
FlatHashTableChunks(std::initializer_list<Node> nodes) { FlatHashTableChunks(std::initializer_list<Node> nodes) {
reserve(nodes.size()); reserve(nodes.size());
for (auto &node : reversed(nodes)) { for (auto &node : nodes) {
CHECK(!node.empty()); CHECK(!node.empty());
if (count(node.first) > 0) { if (count(node.key()) > 0) {
continue; continue;
} }
emplace_node(Node{node.first, node.second}); emplace_node(Node{node.first, node.second});

View File

@ -276,8 +276,6 @@ class FlatHashTable {
break; break;
} }
if (EqT()(node.key(), new_node.key())) { if (EqT()(node.key(), new_node.key())) {
node.clear();
node.copy_from(new_node);
break; break;
} }
next_bucket(bucket); next_bucket(bucket);

View File

@ -181,14 +181,12 @@ struct reversion_wrapper {
template <typename T> template <typename T>
auto begin(reversion_wrapper<T> w) { auto begin(reversion_wrapper<T> w) {
using std::rbegin; return w.iterable.rbegin();
return rbegin(w.iterable);
} }
template <typename T> template <typename T>
auto end(reversion_wrapper<T> w) { auto end(reversion_wrapper<T> w) {
using std::rend; return w.iterable.rend();
return rend(w.iterable);
} }
} // namespace detail } // namespace detail

View File

@ -119,7 +119,7 @@ TEST(FlatHashMap, basic) {
{ {
td::FlatHashMap<int, td::string> map = {{1, "hello"}, {1, "world"}}; td::FlatHashMap<int, td::string> map = {{1, "hello"}, {1, "world"}};
ASSERT_EQ("world", map[1]); ASSERT_EQ("hello", map[1]);
ASSERT_EQ(1u, map.size()); ASSERT_EQ(1u, map.size());
} }