summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authordgolear <[email protected]>2025-07-10 22:33:21 +0300
committerdgolear <[email protected]>2025-07-10 22:56:45 +0300
commit5f7c8cead6f7a3f7bea3f01cb168eb1f7a926879 (patch)
tree96517df0eaef6d7553ad127257902f0ff0707e4a /library
parent612146bc655489da23249308c666ca9eb2ef6509 (diff)
YT: Allow serializing TCompactSet
commit_hash:733610a293a0c3a2656dbef77630d359c16d3bdf
Diffstat (limited to 'library')
-rw-r--r--library/cpp/yt/compact_containers/compact_flat_map-inl.h18
-rw-r--r--library/cpp/yt/compact_containers/compact_flat_map.h5
-rw-r--r--library/cpp/yt/compact_containers/compact_set-inl.h28
-rw-r--r--library/cpp/yt/compact_containers/compact_set.h17
4 files changed, 45 insertions, 23 deletions
diff --git a/library/cpp/yt/compact_containers/compact_flat_map-inl.h b/library/cpp/yt/compact_containers/compact_flat_map-inl.h
index e781569d9da..7bc52cbb1bb 100644
--- a/library/cpp/yt/compact_containers/compact_flat_map-inl.h
+++ b/library/cpp/yt/compact_containers/compact_flat_map-inl.h
@@ -21,18 +21,6 @@ TCompactFlatMap<TKey, TValue, N, TKeyCompare>::TCompactFlatMap(std::initializer_
{ }
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 TKey, class TValue, size_t N, class TKeyCompare>
-bool TCompactFlatMap<TKey, TValue, N, TKeyCompare>::operator!=(const TCompactFlatMap& rhs) const
-{
- return !(*this == rhs);
-}
-
-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();
@@ -130,18 +118,18 @@ bool TCompactFlatMap<TKey, TValue, N, TKeyCompare>::contains(const TOtherKey& k)
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);
+ return DoInsert(value);
}
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));
+ return DoInsert(std::move(value));
}
template <class TKey, class TValue, size_t N, class TKeyCompare>
template <class TArg>
-auto TCompactFlatMap<TKey, TValue, N, TKeyCompare>::do_insert(TArg&& value) -> std::pair<iterator, bool>
+auto TCompactFlatMap<TKey, TValue, N, TKeyCompare>::DoInsert(TArg&& value) -> std::pair<iterator, bool>
{
auto [rangeBegin, rangeEnd] = equal_range(value.first);
if (rangeBegin != rangeEnd) {
diff --git a/library/cpp/yt/compact_containers/compact_flat_map.h b/library/cpp/yt/compact_containers/compact_flat_map.h
index 49c8628c46c..65e3f2bff4b 100644
--- a/library/cpp/yt/compact_containers/compact_flat_map.h
+++ b/library/cpp/yt/compact_containers/compact_flat_map.h
@@ -61,8 +61,7 @@ public:
TCompactFlatMap(std::initializer_list<value_type> values);
- bool operator==(const TCompactFlatMap& rhs) const;
- bool operator!=(const TCompactFlatMap& rhs) const;
+ bool operator==(const TCompactFlatMap& rhs) const = default;
iterator begin();
const_iterator begin() const;
@@ -122,7 +121,7 @@ private:
TStorage Storage_;
template <class TArg>
- std::pair<iterator, bool> do_insert(TArg&& value);
+ std::pair<iterator, bool> DoInsert(TArg&& value);
};
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/compact_containers/compact_set-inl.h b/library/cpp/yt/compact_containers/compact_set-inl.h
index 20736f50833..9842d08fe03 100644
--- a/library/cpp/yt/compact_containers/compact_set-inl.h
+++ b/library/cpp/yt/compact_containers/compact_set-inl.h
@@ -208,6 +208,34 @@ TCompactSet<T, N, C, A>::TCompactSet(const A& allocator)
{ }
template <typename T, size_t N, typename C, typename A>
+template <typename TIterator>
+TCompactSet<T, N, C, A>::TCompactSet(TIterator first, TIterator last)
+{
+ insert(first, last);
+}
+
+template <typename T, size_t N, typename C, typename A>
+TCompactSet<T, N, C, A>::TCompactSet(std::initializer_list<key_type> values)
+{
+ insert(values.begin(), values.end());
+}
+
+template <typename T, size_t N, typename C, typename A>
+bool TCompactSet<T, N, C, A>::operator==(const TCompactSet& rhs) const
+{
+ if (size() != rhs.size()) {
+ return false;
+ }
+
+ for (const auto& value : *this) {
+ if (!rhs.contains(value)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+template <typename T, size_t N, typename C, typename A>
bool TCompactSet<T, N, C, A>::empty() const
{
return Vector_.empty() && Set_.empty();
diff --git a/library/cpp/yt/compact_containers/compact_set.h b/library/cpp/yt/compact_containers/compact_set.h
index 354fad195cd..ce89bfb66ae 100644
--- a/library/cpp/yt/compact_containers/compact_set.h
+++ b/library/cpp/yt/compact_containers/compact_set.h
@@ -41,26 +41,33 @@ public:
class const_iterator;
using size_type = std::size_t;
using key_type = T;
+ using value_type = T;
TCompactSet() = default;
TCompactSet(const A& allocator);
+ template <class TIterator>
+ TCompactSet(TIterator first, TIterator last);
+ TCompactSet(std::initializer_list<key_type> values);
+
+ bool operator==(const TCompactSet& rhs) const;
+
[[nodiscard]] bool empty() const;
size_type size() const;
const T& front() const;
- size_type count(const T& v) const;
+ size_type count(const T& value) const;
- bool contains(const T& v) const;
+ bool contains(const T& value) const;
- std::pair<const_iterator, bool> insert(const T& v);
+ std::pair<const_iterator, bool> insert(const T& value);
template <typename TIter>
- void insert(TIter i, TIter e);
+ void insert(TIter first, TIter last);
- bool erase(const T& v);
+ bool erase(const T& value);
void clear();