diff options
| author | robot-piglet <[email protected]> | 2026-04-10 12:58:27 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2026-04-10 13:19:48 +0300 |
| commit | a589fd4b7b19674aad82ba4969967be61ff6ad03 (patch) | |
| tree | db3c56657c87029e95d6489a7d9990e9203a25c5 /library/cpp/containers | |
| parent | 293d3ee5e1666e1c77175f3a65b8ce080969d269 (diff) | |
Intermediate changes
commit_hash:1f5f18fdf0f2495984459d943dd860d4ae2c6202
Diffstat (limited to 'library/cpp/containers')
| -rw-r--r-- | library/cpp/containers/dense_hash/dense_hash.h | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/library/cpp/containers/dense_hash/dense_hash.h b/library/cpp/containers/dense_hash/dense_hash.h index b5feb16eefb..a3ada43ff87 100644 --- a/library/cpp/containers/dense_hash/dense_hash.h +++ b/library/cpp/containers/dense_hash/dense_hash.h @@ -10,6 +10,8 @@ #include <util/str_stl.h> #include <util/ysaveload.h> +#include <iterator> + /* * There are 2 classes in this file: * - TDenseHash - analog of THashMap @@ -38,8 +40,8 @@ private: template <class THash2, class TVal2> friend class TIteratorBase; - THash* Hash; - size_t Idx; + THash* Hash = nullptr; + size_t Idx = 0; // used only to implement end() TIteratorBase(THash* hash, size_t initIdx) @@ -49,6 +51,15 @@ private: } public: + using iterator_concept = std::forward_iterator_tag; + using iterator_category = std::forward_iterator_tag; + using value_type = std::remove_const_t<TVal>; + using difference_type = std::ptrdiff_t; + using pointer = TVal*; + using reference = TVal&; + + TIteratorBase() = default; + TIteratorBase(THash& hash) : Hash(&hash) , Idx(0) @@ -67,10 +78,6 @@ private: TIteratorBase(const TIteratorBase&) = default; - static TIteratorBase CreateEmpty() { - return TIteratorBase(nullptr, 0); - } - TIteratorBase& operator=(const TIteratorBase&) = default; void Next() { @@ -85,15 +92,17 @@ private: return *this; } - TVal& operator*() { - return Hash->Buckets[Idx]; + TIteratorBase operator++(int) { + TIteratorBase tmp = *this; + Next(); + return tmp; } - TVal* operator->() { - return &Hash->Buckets[Idx]; + TVal& operator*() const { + return Hash->Buckets[Idx]; } - const TVal* operator->() const { + TVal* operator->() const { return &Hash->Buckets[Idx]; } @@ -128,6 +137,9 @@ public: using iterator = TIteratorBase<TDenseHash, value_type>; using const_iterator = TIteratorBase<const TDenseHash, const value_type>; + static_assert(std::forward_iterator<iterator>); + static_assert(std::forward_iterator<const_iterator>); + public: TDenseHash(const key_type& emptyMarker = key_type{}, size_type initSize = 0) : EmptyMarker(emptyMarker) @@ -526,8 +538,8 @@ private: class TIteratorBase { friend class TDenseHashSet; - THash* Hash; - size_t Idx; + THash* Hash = nullptr; + size_t Idx = 0; // used only to implement end() TIteratorBase(THash* hash, size_t initIdx) @@ -537,6 +549,15 @@ private: } public: + using iterator_concept = std::forward_iterator_tag; + using iterator_category = std::forward_iterator_tag; + using value_type = TKey; + using difference_type = std::ptrdiff_t; + using pointer = const TKey*; + using reference = const TKey&; + + TIteratorBase() = default; + TIteratorBase(THash& hash) : Hash(&hash) , Idx(0) @@ -558,6 +579,12 @@ private: return *this; } + TIteratorBase operator++(int) { + TIteratorBase tmp = *this; + Next(); + return tmp; + } + bool Initialized() const { return Hash != nullptr; } @@ -570,6 +597,10 @@ private: return Key(); } + const TKey* operator->() const { + return &Hash->Buckets[Idx]; + } + const TKey& Key() const { return Hash->Buckets[Idx]; } @@ -587,6 +618,8 @@ private: public: typedef TIteratorBase<const TDenseHashSet> TConstIterator; + static_assert(std::forward_iterator<TConstIterator>); + TConstIterator begin() const { return TConstIterator(*this); } |
