Move non-template FlatHashTable functions to cpp.

This commit is contained in:
levlam 2022-03-09 18:16:59 +03:00
parent 07bb129653
commit eac8550ec6
3 changed files with 30 additions and 12 deletions

View File

@ -96,6 +96,7 @@ set(TDUTILS_SOURCE
td/utils/FileLog.cpp td/utils/FileLog.cpp
td/utils/filesystem.cpp td/utils/filesystem.cpp
td/utils/find_boundary.cpp td/utils/find_boundary.cpp
td/utils/FlatHashTable.cpp
td/utils/Gzip.cpp td/utils/Gzip.cpp
td/utils/GzipByteFlow.cpp td/utils/GzipByteFlow.cpp
td/utils/Hints.cpp td/utils/Hints.cpp

View File

@ -0,0 +1,25 @@
//
// 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/bits.h"
#include "td/utils/common.h"
#include "td/utils/Random.h"
namespace td {
namespace detail {
uint32 normalize_flat_hash_table_size(uint32 size) {
return td::max(static_cast<uint32>(1) << (32 - count_leading_zeroes32(size)), static_cast<uint32>(8));
}
uint32 get_random_flat_hash_table_bucket(uint32 bucket_count_mask) {
return Random::fast_uint32() & bucket_count_mask;
}
} // namespace detail
} // namespace td

View File

@ -6,15 +6,12 @@
// //
#pragma once #pragma once
#include "td/utils/bits.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/HashTableUtils.h" #include "td/utils/HashTableUtils.h"
#include "td/utils/MapNode.h" #include "td/utils/MapNode.h"
#include "td/utils/Random.h"
#include "td/utils/SetNode.h" #include "td/utils/SetNode.h"
#include <cstddef> #include <cstddef>
#include <functional>
#include <initializer_list> #include <initializer_list>
#include <iterator> #include <iterator>
#include <utility> #include <utility>
@ -22,13 +19,8 @@
namespace td { namespace td {
namespace detail { namespace detail {
inline uint32 normalize_flat_hash_table_size(uint32 size) { uint32 normalize_flat_hash_table_size(uint32 size);
return td::max(static_cast<uint32>(1) << (32 - count_leading_zeroes32(size)), static_cast<uint32>(8)); uint32 get_random_flat_hash_table_bucket(uint32 bucket_count_mask);
}
inline uint32 get_random_flat_hash_table_bucket(uint32 bucket_count_mask) {
return Random::fast_uint32() & bucket_count_mask;
}
} // namespace detail } // namespace detail
template <class NodeT, class HashT, class EqT> template <class NodeT, class HashT, class EqT>
@ -56,7 +48,7 @@ class FlatHashTable {
using value_type = typename NodeT::public_type; using value_type = typename NodeT::public_type;
struct Iterator { struct Iterator {
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
using value_type = FlatHashTable::value_type; using value_type = FlatHashTable::value_type;
using pointer = value_type *; using pointer = value_type *;
@ -108,7 +100,7 @@ class FlatHashTable {
}; };
struct ConstIterator { struct ConstIterator {
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
using value_type = FlatHashTable::value_type; using value_type = FlatHashTable::value_type;
using pointer = const value_type *; using pointer = const value_type *;