diff --git a/tdutils/test/ConcurrentHashMap.cpp b/tdutils/test/ConcurrentHashMap.cpp index afdb8aea8..a4fdf191d 100644 --- a/tdutils/test/ConcurrentHashMap.cpp +++ b/tdutils/test/ConcurrentHashMap.cpp @@ -32,19 +32,17 @@ #include #endif -namespace td { - // Non resizable HashMap. Just an example template class ArrayHashMap { public: - explicit ArrayHashMap(size_t n) : array_(n) { + explicit ArrayHashMap(std::size_t n) : array_(n) { } struct Node { std::atomic key{KeyT{}}; std::atomic value{ValueT{}}; }; - static std::string get_name() { + static td::string get_name() { return "ArrayHashMap"; } KeyT empty_key() const { @@ -60,15 +58,15 @@ class ArrayHashMap { } private: - AtomicHashArray> array_; + td::AtomicHashArray> array_; }; template class ConcurrentHashMapMutex { public: - explicit ConcurrentHashMapMutex(size_t) { + explicit ConcurrentHashMapMutex(std::size_t) { } - static std::string get_name() { + static td::string get_name() { return "ConcurrentHashMapMutex"; } void insert(KeyT key, ValueT value) { @@ -85,7 +83,7 @@ class ConcurrentHashMapMutex { } private: - Mutex mutex_; + td::Mutex mutex_; #if TD_HAVE_ABSL absl::flat_hash_map hash_map_; #else @@ -98,7 +96,7 @@ class ConcurrentHashMapSpinlock { public: explicit ConcurrentHashMapSpinlock(size_t) { } - static std::string get_name() { + static td::string get_name() { return "ConcurrentHashMapSpinlock"; } void insert(KeyT key, ValueT value) { @@ -115,7 +113,7 @@ class ConcurrentHashMapSpinlock { } private: - SpinLock spinlock_; + td::SpinLock spinlock_; #if TD_HAVE_ABSL absl::flat_hash_map hash_map_; #else @@ -129,7 +127,7 @@ class ConcurrentHashMapLibcuckoo { public: explicit ConcurrentHashMapLibcuckoo(size_t) { } - static std::string get_name() { + static td::string get_name() { return "ConcurrentHashMapLibcuckoo"; } void insert(KeyT key, ValueT value) { @@ -149,9 +147,9 @@ class ConcurrentHashMapLibcuckoo { template class ConcurrentHashMapJunction { public: - explicit ConcurrentHashMapJunction(size_t size) : hash_map_() { + explicit ConcurrentHashMapJunction(std::size_t size) : hash_map_() { } - static std::string get_name() { + static td::string get_name() { return "ConcurrentHashMapJunction"; } void insert(KeyT key, ValueT value) { @@ -174,25 +172,23 @@ class ConcurrentHashMapJunction { }; #endif -} // namespace td - template class HashMapBenchmark final : public td::Benchmark { struct Query { int key; int value; }; - std::vector queries; + td::vector queries; td::unique_ptr hash_map; - size_t threads_n = 16; - static constexpr size_t MUL = 7273; //1000000000 + 7; + std::size_t threads_n = 16; + static constexpr std::size_t MUL = 7273; //1000000000 + 7; int n_ = 0; public: - explicit HashMapBenchmark(size_t threads_n) : threads_n(threads_n) { + explicit HashMapBenchmark(std::size_t threads_n) : threads_n(threads_n) { } - std::string get_description() const final { + td::string get_description() const final { return HashMap::get_name(); } void start_up_n(int n) final { @@ -203,11 +199,11 @@ class HashMapBenchmark final : public td::Benchmark { void run(int n) final { n = n_; - std::vector threads; + td::vector threads; - for (size_t i = 0; i < threads_n; i++) { - size_t l = n * i / threads_n; - size_t r = n * (i + 1) / threads_n; + for (std::size_t i = 0; i < threads_n; i++) { + std::size_t l = n * i / threads_n; + std::size_t r = n * (i + 1) / threads_n; threads.emplace_back([l, r, this] { for (size_t i = l; i < r; i++) { auto x = td::narrow_cast((i + 1) * MUL % n_) + 3; @@ -240,14 +236,14 @@ static void bench_hash_map() { TEST(ConcurrentHashMap, Benchmark) { bench_hash_map>(); - bench_hash_map>(); - bench_hash_map>(); - bench_hash_map>(); + bench_hash_map>(); + bench_hash_map>(); + bench_hash_map>(); #if TD_WITH_LIBCUCKOO - bench_hash_map>(); + bench_hash_map>(); #endif #if TD_WITH_JUNCTION - bench_hash_map>(); + bench_hash_map>(); #endif }