From 9e8b2489bd69644b2da7716f7a249c28b1af61e8 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 21 Feb 2022 00:33:19 +0300 Subject: [PATCH] Keep the first value from initializer_list. --- tdutils/td/utils/FlatHashMap.h | 8 ++++---- tdutils/td/utils/FlatHashMapChunks.h | 5 ++--- tdutils/td/utils/FlatHashMapLinear.h | 2 -- tdutils/td/utils/algorithm.h | 6 ++---- tdutils/test/HashSet.cpp | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tdutils/td/utils/FlatHashMap.h b/tdutils/td/utils/FlatHashMap.h index c1bd4ef47..097d02939 100644 --- a/tdutils/td/utils/FlatHashMap.h +++ b/tdutils/td/utils/FlatHashMap.h @@ -14,13 +14,13 @@ namespace td { template , class EqT = std::equal_to> -using FlatHashMap = FlatHashMapImpl; -//using FlatHashMap = FlatHashMapChunks; +//using FlatHashMap = FlatHashMapImpl; +using FlatHashMap = FlatHashMapChunks; //using FlatHashMap = std::unordered_map; template , class EqT = std::equal_to> -using FlatHashSet = FlatHashSetImpl; -//using FlatHashSet = FlatHashSetChunks; +//using FlatHashSet = FlatHashSetImpl; +using FlatHashSet = FlatHashSetChunks; //using FlatHashSet = std::unordered_set; } // namespace td diff --git a/tdutils/td/utils/FlatHashMapChunks.h b/tdutils/td/utils/FlatHashMapChunks.h index 765521b65..aaa9f532c 100644 --- a/tdutils/td/utils/FlatHashMapChunks.h +++ b/tdutils/td/utils/FlatHashMapChunks.h @@ -6,7 +6,6 @@ // #pragma once -#include "td/utils/algorithm.h" #include "td/utils/bits.h" #include "td/utils/common.h" #include "td/utils/FlatHashMapLinear.h" @@ -224,9 +223,9 @@ class FlatHashTableChunks { FlatHashTableChunks(std::initializer_list nodes) { reserve(nodes.size()); - for (auto &node : reversed(nodes)) { + for (auto &node : nodes) { CHECK(!node.empty()); - if (count(node.first) > 0) { + if (count(node.key()) > 0) { continue; } emplace_node(Node{node.first, node.second}); diff --git a/tdutils/td/utils/FlatHashMapLinear.h b/tdutils/td/utils/FlatHashMapLinear.h index 4dcd6788b..d9b3ebb15 100644 --- a/tdutils/td/utils/FlatHashMapLinear.h +++ b/tdutils/td/utils/FlatHashMapLinear.h @@ -276,8 +276,6 @@ class FlatHashTable { break; } if (EqT()(node.key(), new_node.key())) { - node.clear(); - node.copy_from(new_node); break; } next_bucket(bucket); diff --git a/tdutils/td/utils/algorithm.h b/tdutils/td/utils/algorithm.h index 32c94fdb6..0c3702d8c 100644 --- a/tdutils/td/utils/algorithm.h +++ b/tdutils/td/utils/algorithm.h @@ -181,14 +181,12 @@ struct reversion_wrapper { template auto begin(reversion_wrapper w) { - using std::rbegin; - return rbegin(w.iterable); + return w.iterable.rbegin(); } template auto end(reversion_wrapper w) { - using std::rend; - return rend(w.iterable); + return w.iterable.rend(); } } // namespace detail diff --git a/tdutils/test/HashSet.cpp b/tdutils/test/HashSet.cpp index 949918bb4..0d4fa7bea 100644 --- a/tdutils/test/HashSet.cpp +++ b/tdutils/test/HashSet.cpp @@ -119,7 +119,7 @@ TEST(FlatHashMap, basic) { { td::FlatHashMap map = {{1, "hello"}, {1, "world"}}; - ASSERT_EQ("world", map[1]); + ASSERT_EQ("hello", map[1]); ASSERT_EQ(1u, map.size()); }