diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index f8a69ecad..a2d9f1b43 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -96,6 +96,7 @@ set(TDUTILS_SOURCE td/utils/FileLog.cpp td/utils/filesystem.cpp td/utils/find_boundary.cpp + td/utils/FlatHashTable.cpp td/utils/Gzip.cpp td/utils/GzipByteFlow.cpp td/utils/Hints.cpp diff --git a/tdutils/td/utils/FlatHashTable.cpp b/tdutils/td/utils/FlatHashTable.cpp new file mode 100644 index 000000000..099febe65 --- /dev/null +++ b/tdutils/td/utils/FlatHashTable.cpp @@ -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(1) << (32 - count_leading_zeroes32(size)), static_cast(8)); +} + +uint32 get_random_flat_hash_table_bucket(uint32 bucket_count_mask) { + return Random::fast_uint32() & bucket_count_mask; +} + +} // namespace detail +} // namespace td diff --git a/tdutils/td/utils/FlatHashTable.h b/tdutils/td/utils/FlatHashTable.h index 2aaae21a4..c962b6435 100644 --- a/tdutils/td/utils/FlatHashTable.h +++ b/tdutils/td/utils/FlatHashTable.h @@ -6,15 +6,12 @@ // #pragma once -#include "td/utils/bits.h" #include "td/utils/common.h" #include "td/utils/HashTableUtils.h" #include "td/utils/MapNode.h" -#include "td/utils/Random.h" #include "td/utils/SetNode.h" #include -#include #include #include #include @@ -22,13 +19,8 @@ namespace td { namespace detail { -inline uint32 normalize_flat_hash_table_size(uint32 size) { - return td::max(static_cast(1) << (32 - count_leading_zeroes32(size)), static_cast(8)); -} - -inline uint32 get_random_flat_hash_table_bucket(uint32 bucket_count_mask) { - return Random::fast_uint32() & bucket_count_mask; -} +uint32 normalize_flat_hash_table_size(uint32 size); +uint32 get_random_flat_hash_table_bucket(uint32 bucket_count_mask); } // namespace detail template @@ -56,7 +48,7 @@ class FlatHashTable { using value_type = typename NodeT::public_type; struct Iterator { - using iterator_category = std::bidirectional_iterator_tag; + using iterator_category = std::forward_iterator_tag; using difference_type = std::ptrdiff_t; using value_type = FlatHashTable::value_type; using pointer = value_type *; @@ -108,7 +100,7 @@ class FlatHashTable { }; struct ConstIterator { - using iterator_category = std::bidirectional_iterator_tag; + using iterator_category = std::forward_iterator_tag; using difference_type = std::ptrdiff_t; using value_type = FlatHashTable::value_type; using pointer = const value_type *;