diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-09-03 11:05:27 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-09-03 11:05:27 +0000 |
commit | 8f71d7ed87007ace129f647b242a09d01773d3c5 (patch) | |
tree | 2c46ca9d89eb0ce5eea79ba1febb79e56efedb0f /library/cpp/yt | |
parent | 78242bd5894abd6548e45731b464822da55a0796 (diff) | |
parent | 3da5a68ec3c329240e89bd0ed8c1c39e4359a693 (diff) | |
download | ydb-8f71d7ed87007ace129f647b242a09d01773d3c5.tar.gz |
Merge branch 'rightlib' into mergelibs-240903-1104
Diffstat (limited to 'library/cpp/yt')
-rw-r--r-- | library/cpp/yt/misc/unaligned-inl.h | 31 | ||||
-rw-r--r-- | library/cpp/yt/misc/unaligned.h | 23 | ||||
-rw-r--r-- | library/cpp/yt/small_containers/compact_flat_map-inl.h | 169 | ||||
-rw-r--r-- | library/cpp/yt/small_containers/compact_flat_map.h | 73 | ||||
-rw-r--r-- | library/cpp/yt/small_containers/compact_set-inl.h | 16 | ||||
-rw-r--r-- | library/cpp/yt/small_containers/compact_set.h | 3 |
6 files changed, 193 insertions, 122 deletions
diff --git a/library/cpp/yt/misc/unaligned-inl.h b/library/cpp/yt/misc/unaligned-inl.h new file mode 100644 index 0000000000..68e1c9b499 --- /dev/null +++ b/library/cpp/yt/misc/unaligned-inl.h @@ -0,0 +1,31 @@ +#ifndef UNALIGNED_INL_H_ +#error "Direct inclusion of this file is not allowed, include unaligned.h" +// For the sake of sane code completion. +#include "unaligned.h" +#endif + +#include <cstring> + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +template <class T> + requires std::is_trivial_v<T> +T UnalignedLoad(const T* ptr) +{ + T value; + std::memcpy(&value, ptr, sizeof(T)); + return value; +} + +template <class T> + requires std::is_trivial_v<T> +void UnalignedStore(T* ptr, const T& value) +{ + std::memcpy(ptr, &value, sizeof(T)); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/library/cpp/yt/misc/unaligned.h b/library/cpp/yt/misc/unaligned.h new file mode 100644 index 0000000000..68c124183f --- /dev/null +++ b/library/cpp/yt/misc/unaligned.h @@ -0,0 +1,23 @@ +#pragma once + +#include <type_traits> + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +template <class T> + requires std::is_trivial_v<T> +T UnalignedLoad(const T* ptr); + +template <class T> + requires std::is_trivial_v<T> +void UnalignedStore(T* ptr, const T& value); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT + +#define UNALIGNED_INL_H_ +#include "unaligned-inl.h" +#undef UNALIGNED_INL_H_ diff --git a/library/cpp/yt/small_containers/compact_flat_map-inl.h b/library/cpp/yt/small_containers/compact_flat_map-inl.h index 459d72fa2c..e781569d9d 100644 --- a/library/cpp/yt/small_containers/compact_flat_map-inl.h +++ b/library/cpp/yt/small_containers/compact_flat_map-inl.h @@ -8,137 +8,140 @@ namespace NYT { /////////////////////////////////////////////////////////////////////////////// -template <class K, class V, size_t N> +template <class TKey, class TValue, size_t N, class TKeyCompare> template <class TInputIterator> -TCompactFlatMap<K, V, N>::TCompactFlatMap(TInputIterator begin, TInputIterator end) +TCompactFlatMap<TKey, TValue, N, TKeyCompare>::TCompactFlatMap(TInputIterator begin, TInputIterator end) { insert(begin, end); } -template <class K, class V, size_t N> -TCompactFlatMap<K, V, N>::TCompactFlatMap(std::initializer_list<value_type> values) - : TCompactFlatMap<K, V, N>(values.begin(), values.end()) +template <class TKey, class TValue, size_t N, class TKeyCompare> +TCompactFlatMap<TKey, TValue, N, TKeyCompare>::TCompactFlatMap(std::initializer_list<value_type> values) + : TCompactFlatMap<TKey, TValue, N, TKeyCompare>(values.begin(), values.end()) { } -template <class K, class V, size_t N> -bool TCompactFlatMap<K, V, N>::operator==(const TCompactFlatMap& rhs) const +template <class TKey, class TValue, size_t N, class TKeyCompare> +bool TCompactFlatMap<TKey, TValue, N, TKeyCompare>::operator==(const TCompactFlatMap& rhs) const { return Storage_ == rhs.Storage_; } -template <class K, class V, size_t N> -bool TCompactFlatMap<K, V, N>::operator!=(const TCompactFlatMap& rhs) const +template <class TKey, class TValue, size_t N, class TKeyCompare> +bool TCompactFlatMap<TKey, TValue, N, TKeyCompare>::operator!=(const TCompactFlatMap& rhs) const { return !(*this == rhs); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::begin() +template <class TKey, class TValue, size_t N, class TKeyCompare> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::begin() { return Storage_.begin(); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::begin() const +template <class TKey, class TValue, size_t N, class TKeyCompare> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::begin() const { return Storage_.begin(); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::cbegin() const +template <class TKey, class TValue, size_t N, class TKeyCompare> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::cbegin() const { return Storage_.begin(); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::end() +template <class TKey, class TValue, size_t N, class TKeyCompare> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::end() { return Storage_.end(); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::end() const +template <class TKey, class TValue, size_t N, class TKeyCompare> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::end() const { return Storage_.end(); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::cend() const +template <class TKey, class TValue, size_t N, class TKeyCompare> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::cend() const { return Storage_.end(); } -template <class K, class V, size_t N> -void TCompactFlatMap<K, V, N>::reserve(size_type n) +template <class TKey, class TValue, size_t N, class TKeyCompare> +void TCompactFlatMap<TKey, TValue, N, TKeyCompare>::reserve(size_type n) { Storage_.reserve(n); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::size_type TCompactFlatMap<K, V, N>::size() const +template <class TKey, class TValue, size_t N, class TKeyCompare> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::size_type TCompactFlatMap<TKey, TValue, N, TKeyCompare>::size() const { return Storage_.size(); } -template <class K, class V, size_t N> -int TCompactFlatMap<K, V, N>::ssize() const +template <class TKey, class TValue, size_t N, class TKeyCompare> +int TCompactFlatMap<TKey, TValue, N, TKeyCompare>::ssize() const { return static_cast<int>(Storage_.size()); } -template <class K, class V, size_t N> -bool TCompactFlatMap<K, V, N>::empty() const +template <class TKey, class TValue, size_t N, class TKeyCompare> +bool TCompactFlatMap<TKey, TValue, N, TKeyCompare>::empty() const { return Storage_.empty(); } -template <class K, class V, size_t N> -void TCompactFlatMap<K, V, N>::clear() +template <class TKey, class TValue, size_t N, class TKeyCompare> +void TCompactFlatMap<TKey, TValue, N, TKeyCompare>::clear() { Storage_.clear(); } -template <class K, class V, size_t N> -void TCompactFlatMap<K, V, N>::shrink_to_small() +template <class TKey, class TValue, size_t N, class TKeyCompare> +void TCompactFlatMap<TKey, TValue, N, TKeyCompare>::shrink_to_small() { Storage_.shrink_to_small(); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::find(const K& k) +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::find(const TOtherKey& k) { auto [rangeBegin, rangeEnd] = equal_range(k); return rangeBegin == rangeEnd ? end() : rangeBegin; } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::find(const K& k) const +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::find(const TOtherKey& k) const { auto [rangeBegin, rangeEnd] = equal_range(k); return rangeBegin == rangeEnd ? end() : rangeBegin; } -template <class K, class V, size_t N> -bool TCompactFlatMap<K, V, N>::contains(const K& k) const +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +bool TCompactFlatMap<TKey, TValue, N, TKeyCompare>::contains(const TOtherKey& k) const { return find(k) != end(); } -template <class K, class V, size_t N> -auto TCompactFlatMap<K, V, N>::insert(const value_type& value) -> std::pair<iterator, bool> +template <class TKey, class TValue, size_t N, class TKeyCompare> +auto TCompactFlatMap<TKey, TValue, N, TKeyCompare>::insert(const value_type& value) -> std::pair<iterator, bool> { return do_insert(value); } -template <class K, class V, size_t N> -auto TCompactFlatMap<K, V, N>::insert(value_type&& value) -> std::pair<iterator, bool> +template <class TKey, class TValue, size_t N, class TKeyCompare> +auto TCompactFlatMap<TKey, TValue, N, TKeyCompare>::insert(value_type&& value) -> std::pair<iterator, bool> { return do_insert(std::move(value)); } -template <class K, class V, size_t N> +template <class TKey, class TValue, size_t N, class TKeyCompare> template <class TArg> -auto TCompactFlatMap<K, V, N>::do_insert(TArg&& value) -> std::pair<iterator, bool> +auto TCompactFlatMap<TKey, TValue, N, TKeyCompare>::do_insert(TArg&& value) -> std::pair<iterator, bool> { auto [rangeBegin, rangeEnd] = equal_range(value.first); if (rangeBegin != rangeEnd) { @@ -149,38 +152,38 @@ auto TCompactFlatMap<K, V, N>::do_insert(TArg&& value) -> std::pair<iterator, bo } } -template <class K, class V, size_t N> +template <class TKey, class TValue, size_t N, class TKeyCompare> template <class TInputIterator> -void TCompactFlatMap<K, V, N>::insert(TInputIterator begin, TInputIterator end) +void TCompactFlatMap<TKey, TValue, N, TKeyCompare>::insert(TInputIterator begin, TInputIterator end) { for (auto it = begin; it != end; ++it) { insert(*it); } } -template <class K, class V, size_t N> +template <class TKey, class TValue, size_t N, class TKeyCompare> template <class... TArgs> -auto TCompactFlatMap<K, V, N>::emplace(TArgs&&... args) -> std::pair<iterator, bool> +auto TCompactFlatMap<TKey, TValue, N, TKeyCompare>::emplace(TArgs&&... args) -> std::pair<iterator, bool> { return insert(value_type(std::forward<TArgs>(args)...)); } -template <class K, class V, size_t N> -V& TCompactFlatMap<K, V, N>::operator[](const K& k) +template <class TKey, class TValue, size_t N, class TKeyCompare> +TValue& TCompactFlatMap<TKey, TValue, N, TKeyCompare>::operator[](const TKey& k) { - auto [it, inserted] = insert({k, V()}); + auto [it, inserted] = insert({k, TValue()}); return it->second; } -template <class K, class V, size_t N> -void TCompactFlatMap<K, V, N>::erase(const K& k) +template <class TKey, class TValue, size_t N, class TKeyCompare> +void TCompactFlatMap<TKey, TValue, N, TKeyCompare>::erase(const TKey& k) { auto [rangeBegin, rangeEnd] = equal_range(k); erase(rangeBegin, rangeEnd); } -template <class K, class V, size_t N> -void TCompactFlatMap<K, V, N>::erase(iterator pos) +template <class TKey, class TValue, size_t N, class TKeyCompare> +void TCompactFlatMap<TKey, TValue, N, TKeyCompare>::erase(iterator pos) { Storage_.erase(pos); @@ -188,8 +191,8 @@ void TCompactFlatMap<K, V, N>::erase(iterator pos) Storage_.shrink_to_small(); } -template <class K, class V, size_t N> -void TCompactFlatMap<K, V, N>::erase(iterator b, iterator e) +template <class TKey, class TValue, size_t N, class TKeyCompare> +void TCompactFlatMap<TKey, TValue, N, TKeyCompare>::erase(iterator b, iterator e) { Storage_.erase(b, e); @@ -197,46 +200,52 @@ void TCompactFlatMap<K, V, N>::erase(iterator b, iterator e) Storage_.shrink_to_small(); } -template <class K, class V, size_t N> -std::pair<typename TCompactFlatMap<K, V, N>::iterator, typename TCompactFlatMap<K, V, N>::iterator> -TCompactFlatMap<K, V, N>::equal_range(const K& k) +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +std::pair<typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator, typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator> +TCompactFlatMap<TKey, TValue, N, TKeyCompare>::equal_range(const TOtherKey& k) { - auto result = std::equal_range(Storage_.begin(), Storage_.end(), k, TKeyComparer()); - YT_ASSERT(std::distance(result.first, result.second) <= 1); + auto result = std::ranges::equal_range(Storage_, k, {}, &value_type::first); + YT_ASSERT(result.size() <= 1); return result; } -template <class K, class V, size_t N> -std::pair<typename TCompactFlatMap<K, V, N>::const_iterator, typename TCompactFlatMap<K, V, N>::const_iterator> -TCompactFlatMap<K, V, N>::equal_range(const K& k) const +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +std::pair<typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator, typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator> +TCompactFlatMap<TKey, TValue, N, TKeyCompare>::equal_range(const TOtherKey& k) const { - auto result = std::equal_range(Storage_.begin(), Storage_.end(), k, TKeyComparer()); - YT_ASSERT(std::distance(result.first, result.second) <= 1); + auto result = std::ranges::equal_range(Storage_, k, {}, &value_type::first); + YT_ASSERT(result.size() <= 1); return result; } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::lower_bound(const K& k) const +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::lower_bound(const TOtherKey& k) const { - return std::lower_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); + return std::ranges::lower_bound(Storage_, k, {}, &value_type::first); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::lower_bound(const K& k) +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::lower_bound(const TOtherKey& k) { - return std::lower_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); + return std::ranges::lower_bound(Storage_, k, {}, &value_type::first); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::upper_bound(const K& k) const +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::upper_bound(const TOtherKey& k) const { - return std::upper_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); + return std::ranges::upper_bound(Storage_, k, {}, &value_type::first); } -template <class K, class V, size_t N> -typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::upper_bound(const K& k) +template <class TKey, class TValue, size_t N, class TKeyCompare> +template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> +typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::upper_bound(const TOtherKey& k) { - return std::upper_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); + return std::ranges::upper_bound(Storage_, k, {}, &value_type::first); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/small_containers/compact_flat_map.h b/library/cpp/yt/small_containers/compact_flat_map.h index b598a34731..120c2141b9 100644 --- a/library/cpp/yt/small_containers/compact_flat_map.h +++ b/library/cpp/yt/small_containers/compact_flat_map.h @@ -4,9 +4,21 @@ namespace NYT { +namespace NDetail { + +template <typename T> +concept CHasIsTransparentFlag = requires { + typename T::is_transparent; +}; + +template <typename T, typename U, typename TCompare> +concept CComparisonAllowed = std::same_as<T, U> || CHasIsTransparentFlag<TCompare>; + +} // namespace NDetail + /////////////////////////////////////////////////////////////////////////////// -//! A flat map implementation over TCompactVector that tries to keep data inline. +//! A flat map implementation over TCompactTValueector that tries to keep data inline. /*! * Similarly to SmallSet, this is implemented via binary search over a sorted * vector. Unlike SmallSet, however, this one never falls back to std::map (or @@ -21,32 +33,20 @@ namespace NYT { * Because of the latter, one should be very careful with iterators: virtually * any call to insert or erase may potentially invalidate all iterators. */ -template <class K, class V, size_t N> +template <class TKey, class TValue, size_t N, class TKeyCompare = std::ranges::less> class TCompactFlatMap { public: - // NB: can't make this pair<const K, V> as TCompactVector requires its type + // NB: can't make this pair<const TKey, TValue> as TCompactTValueector requires its type // parameter to be copy-assignable. - using value_type = std::pair<K, V>; - using key_type = K; - using mapped_type = V; + using value_type = std::pair<TKey, TValue>; + using key_type = TKey; + using mapped_type = TValue; + using key_compare = TKeyCompare; private: using TStorage = TCompactVector<value_type, N>; - struct TKeyComparer - { - bool operator()(const K& lhs, const value_type& rhs) - { - return lhs < rhs.first; - } - - bool operator()(const value_type& lhs, const K& rhs) - { - return lhs.first < rhs; - } - }; - public: using iterator = typename TStorage::iterator; using const_iterator = typename TStorage::const_iterator; @@ -80,17 +80,26 @@ public: void shrink_to_small(); - iterator find(const K& k); - const_iterator find(const K& k) const; - - iterator lower_bound(const K& k); - const_iterator lower_bound(const K& k) const; - iterator upper_bound(const K& k); - const_iterator upper_bound(const K& k) const; - std::pair<iterator, iterator> equal_range(const K& k); - std::pair<const_iterator, const_iterator> equal_range(const K& k) const; - - bool contains(const K& k) const; + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + iterator find(const TOtherKey& k); + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + const_iterator find(const TOtherKey& k) const; + + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + iterator lower_bound(const TOtherKey& k); + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + const_iterator lower_bound(const TOtherKey& k) const; + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + iterator upper_bound(const TOtherKey& k); + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + const_iterator upper_bound(const TOtherKey& k) const; + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + std::pair<iterator, iterator> equal_range(const TOtherKey& k); + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + std::pair<const_iterator, const_iterator> equal_range(const TOtherKey& k) const; + + template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey> + bool contains(const TOtherKey& k) const; std::pair<iterator, bool> insert(const value_type& value); std::pair<iterator, bool> insert(value_type&& value); @@ -101,9 +110,9 @@ public: template <class... TArgs> std::pair<iterator, bool> emplace(TArgs&&... args); - V& operator[](const K& k); + TValue& operator[](const TKey& k); - void erase(const K& k); + void erase(const TKey& k); void erase(iterator pos); void erase(iterator b, iterator e); diff --git a/library/cpp/yt/small_containers/compact_set-inl.h b/library/cpp/yt/small_containers/compact_set-inl.h index e93d11f126..20736f5083 100644 --- a/library/cpp/yt/small_containers/compact_set-inl.h +++ b/library/cpp/yt/small_containers/compact_set-inl.h @@ -216,19 +216,19 @@ bool TCompactSet<T, N, C, A>::empty() const template <typename T, size_t N, typename C, typename A> typename TCompactSet<T, N, C, A>::size_type TCompactSet<T, N, C, A>::size() const { - return is_small() ? Vector_.size() : Set_.size(); + return IsSmall() ? Vector_.size() : Set_.size(); } template <typename T, size_t N, typename C, typename A> const T& TCompactSet<T, N, C, A>::front() const { - return is_small() ? Vector_.front() : *Set_.begin(); + return IsSmall() ? Vector_.front() : *Set_.begin(); } template <typename T, size_t N, typename C, typename A> typename TCompactSet<T, N, C, A>::size_type TCompactSet<T, N, C, A>::count(const T& v) const { - if (is_small()) { + if (IsSmall()) { return std::binary_search(Vector_.begin(), Vector_.end(), v, C()) ? 1 : 0; } else { return Set_.count(v); @@ -244,7 +244,7 @@ bool TCompactSet<T, N, C, A>::contains(const T& v) const template <typename T, size_t N, typename C, typename A> std::pair<typename TCompactSet<T, N, C, A>::const_iterator, bool> TCompactSet<T, N, C, A>::insert(const T& v) { - if (!is_small()) { + if (!IsSmall()) { auto [it, inserted] = Set_.insert(v); return {const_iterator(std::move(it)), inserted}; } @@ -279,7 +279,7 @@ void TCompactSet<T, N, C, A>::insert(TIter i, TIter e) template <typename T, size_t N, typename C, typename A> bool TCompactSet<T, N, C, A>::erase(const T& v) { - if (!is_small()) { + if (!IsSmall()) { return Set_.erase(v); } @@ -302,7 +302,7 @@ void TCompactSet<T, N, C, A>::clear() template <typename T, size_t N, typename C, typename A> typename TCompactSet<T, N, C, A>::const_iterator TCompactSet<T, N, C, A>::begin() const { - return is_small() ? const_iterator(Vector_.begin()) : const_iterator(Set_.begin()); + return IsSmall() ? const_iterator(Vector_.begin()) : const_iterator(Set_.begin()); } template <typename T, size_t N, typename C, typename A> @@ -314,7 +314,7 @@ typename TCompactSet<T, N, C, A>::const_iterator TCompactSet<T, N, C, A>::cbegin template <typename T, size_t N, typename C, typename A> typename TCompactSet<T, N, C, A>::const_iterator TCompactSet<T, N, C, A>::end() const { - return is_small() ? const_iterator(Vector_.end()) : const_iterator(Set_.end()); + return IsSmall() ? const_iterator(Vector_.end()) : const_iterator(Set_.end()); } template <typename T, size_t N, typename C, typename A> @@ -324,7 +324,7 @@ typename TCompactSet<T, N, C, A>::const_iterator TCompactSet<T, N, C, A>::cend() } template <typename T, size_t N, typename C, typename A> -bool TCompactSet<T, N, C, A>::is_small() const +bool TCompactSet<T, N, C, A>::IsSmall() const { return Set_.empty(); } diff --git a/library/cpp/yt/small_containers/compact_set.h b/library/cpp/yt/small_containers/compact_set.h index ca5e3c6efd..354fad195c 100644 --- a/library/cpp/yt/small_containers/compact_set.h +++ b/library/cpp/yt/small_containers/compact_set.h @@ -80,7 +80,7 @@ private: using TSetConstIterator = typename std::set<T, C, A>::const_iterator; using TVectorConstIterator = typename TCompactVector<T, N>::const_iterator; - bool is_small() const; + bool IsSmall() const; }; /////////////////////////////////////////////////////////////////////////////// @@ -90,4 +90,3 @@ private: #define COMPACT_SET_INL_H_ #include "compact_set-inl.h" #undef COMPACT_SET_INL_H_ - |