Add separate FlatHashSet.h.
This commit is contained in:
parent
eac8550ec6
commit
7f7344c363
@ -17,6 +17,7 @@
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/FlatHashSet.h"
|
||||
#include "td/utils/Hints.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
|
@ -208,6 +208,7 @@ set(TDUTILS_SOURCE
|
||||
td/utils/find_boundary.h
|
||||
td/utils/FlatHashMap.h
|
||||
td/utils/FlatHashMapChunks.h
|
||||
td/utils/FlatHashSet.h
|
||||
td/utils/FlatHashTable.h
|
||||
td/utils/FloodControlFast.h
|
||||
td/utils/FloodControlStrict.h
|
||||
|
@ -9,11 +9,9 @@
|
||||
//#include "td/utils/FlatHashMapChunks.h"
|
||||
//#include "td/utils/FlatHashTable.h"
|
||||
//#include "td/utils/MapNode.h"
|
||||
//#include "td/utils/SetNode.h"
|
||||
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -22,9 +20,4 @@ template <class KeyT, class ValueT, class HashT = std::hash<KeyT>, class EqT = s
|
||||
//using FlatHashMap = FlatHashMapChunks<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>>
|
||||
//using FlatHashSet = FlatHashTable<SetNode<KeyT>, HashT, EqT>;
|
||||
//using FlatHashSet = FlatHashSetChunks<KeyT, HashT, EqT>;
|
||||
using FlatHashSet = std::unordered_set<KeyT, HashT, EqT>;
|
||||
|
||||
} // namespace td
|
||||
|
23
tdutils/td/utils/FlatHashSet.h
Normal file
23
tdutils/td/utils/FlatHashSet.h
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
//#include "td/utils/FlatHashMapChunks.h"
|
||||
//#include "td/utils/FlatHashTable.h"
|
||||
//#include "td/utils/SetNode.h"
|
||||
|
||||
#include <functional>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace td {
|
||||
|
||||
template <class KeyT, class HashT = std::hash<KeyT>, class EqT = std::equal_to<KeyT>>
|
||||
//using FlatHashSet = FlatHashTable<SetNode<KeyT>, HashT, EqT>;
|
||||
//using FlatHashSet = FlatHashSetChunks<KeyT, HashT, EqT>;
|
||||
using FlatHashSet = std::unordered_set<KeyT, HashT, EqT>;
|
||||
|
||||
} // namespace td
|
@ -184,6 +184,12 @@ class FlatHashTable {
|
||||
begin_bucket_ = other.begin_bucket_;
|
||||
other.drop();
|
||||
}
|
||||
~FlatHashTable() {
|
||||
if (nodes_ != nullptr) {
|
||||
clear_nodes(nodes_);
|
||||
}
|
||||
}
|
||||
|
||||
void swap(FlatHashTable &other) noexcept {
|
||||
std::swap(nodes_, other.nodes_);
|
||||
std::swap(used_node_count_, other.used_node_count_);
|
||||
@ -191,11 +197,6 @@ class FlatHashTable {
|
||||
std::swap(bucket_count_, other.bucket_count_);
|
||||
std::swap(begin_bucket_, other.begin_bucket_);
|
||||
}
|
||||
~FlatHashTable() {
|
||||
if (nodes_ != nullptr) {
|
||||
clear_nodes(nodes_);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 bucket_count() const {
|
||||
return bucket_count_;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/FlatHashMapChunks.h"
|
||||
#include "td/utils/FlatHashSet.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/Random.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
@ -380,6 +380,7 @@ static void BM_cache3(benchmark::State &state) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TableT>
|
||||
static void BM_remove_if_slow(benchmark::State &state) {
|
||||
constexpr std::size_t N = 5000;
|
||||
@ -405,6 +406,7 @@ static void BM_remove_if_slow(benchmark::State &state) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TableT>
|
||||
static void BM_remove_if_slow_old(benchmark::State &state) {
|
||||
constexpr std::size_t N = 100000;
|
||||
|
Loading…
Reference in New Issue
Block a user