Changeset f63bef0 in mainline
- Timestamp:
- 2018-07-05T21:41:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 275bdafb
- Parents:
- 6b18e43
- git-author:
- Dzejrou <dzejrou@…> (2018-04-28 23:45:37)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/internal/hash_table_iterators.hpp
r6b18e43 rf63bef0 91 91 hash_table_const_iterator operator++(int) 92 92 { 93 auto tmp_current = current_; 94 auto tmp_idx = idx_; 95 93 auto tmp = *this; 94 ++(*this); 95 96 return tmp; 97 } 98 99 list_node<value_type>* node() 100 { 101 return const_cast<list_node<value_type>*>(current_); 102 } 103 104 const list_node<value_type>* node() const 105 { 106 return current_; 107 } 108 109 size_type idx() const 110 { 111 return idx_; 112 } 113 114 private: 115 const hash_table_bucket<value_type, size_type>* table_; 116 size_type idx_; 117 size_type max_idx_; 118 const list_node<value_type>* current_; 119 }; 120 121 template<class Value, class ConstRef, class ConstPtr, class Size> 122 bool operator==(const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& lhs, 123 const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& rhs) 124 { 125 return lhs.node() == rhs.node(); 126 } 127 128 template<class Value, class ConstRef, class ConstPtr, class Size> 129 bool operator!=(const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& lhs, 130 const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& rhs) 131 { 132 return !(lhs == rhs); 133 } 134 135 template<class Value, class Reference, class Pointer, class Size> 136 class hash_table_iterator 137 { 138 public: 139 using value_type = Value; 140 using size_type = Size; 141 using reference = Reference; 142 using pointer = Pointer; 143 using difference_type = ptrdiff_t; 144 145 using iterator_category = forward_iterator_tag; 146 147 hash_table_iterator(hash_table_bucket<value_type, size_type>* table = nullptr, 148 size_type idx = size_type{}, size_type max_idx = size_type{}, 149 list_node<value_type>* current = nullptr) 150 : table_{table}, idx_{idx}, max_idx_{max_idx}, current_{current} 151 { /* DUMMY BODY */ } 152 153 hash_table_iterator(const hash_table_iterator&) = default; 154 hash_table_iterator& operator=(const hash_table_iterator&) = default; 155 156 reference operator*() 157 { 158 return current_->value; 159 } 160 161 pointer operator->() 162 { 163 return ¤t_->value; 164 } 165 166 hash_table_iterator& operator++() 167 { 96 168 current_ = current_->next; 97 169 if (current_ == table_[idx_].head) … … 111 183 } 112 184 113 return hash_table_const_iterator{114 table_, tmp_idx, max_idx_, tmp_current115 };116 }117 118 list_node<value_type>* node()119 {120 return const_cast<list_node<value_type>*>(current_);121 }122 123 const list_node<value_type>* node() const124 {125 return current_;126 }127 128 size_type idx() const129 {130 return idx_;131 }132 133 private:134 const hash_table_bucket<value_type, size_type>* table_;135 size_type idx_;136 size_type max_idx_;137 const list_node<value_type>* current_;138 };139 140 template<class Value, class ConstRef, class ConstPtr, class Size>141 bool operator==(const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& lhs,142 const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& rhs)143 {144 return lhs.node() == rhs.node();145 }146 147 template<class Value, class ConstRef, class ConstPtr, class Size>148 bool operator!=(const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& lhs,149 const hash_table_const_iterator<Value, ConstRef, ConstPtr, Size>& rhs)150 {151 return !(lhs == rhs);152 }153 154 template<class Value, class Reference, class Pointer, class Size>155 class hash_table_iterator156 {157 public:158 using value_type = Value;159 using size_type = Size;160 using reference = Reference;161 using pointer = Pointer;162 using difference_type = ptrdiff_t;163 164 using iterator_category = forward_iterator_tag;165 166 hash_table_iterator(hash_table_bucket<value_type, size_type>* table = nullptr,167 size_type idx = size_type{}, size_type max_idx = size_type{},168 list_node<value_type>* current = nullptr)169 : table_{table}, idx_{idx}, max_idx_{max_idx}, current_{current}170 { /* DUMMY BODY */ }171 172 hash_table_iterator(const hash_table_iterator&) = default;173 hash_table_iterator& operator=(const hash_table_iterator&) = default;174 175 reference operator*()176 {177 return current_->value;178 }179 180 pointer operator->()181 {182 return ¤t_->value;183 }184 185 hash_table_iterator& operator++()186 {187 current_ = current_->next;188 if (current_ == table_[idx_].head)189 {190 if (idx_ < max_idx_)191 {192 while (!table_[++idx_].head && idx_ < max_idx_)193 { /* DUMMY BODY */ }194 195 if (idx_ < max_idx_)196 current_ = table_[idx_].head;197 else198 current_ = nullptr;199 }200 else201 current_ = nullptr;202 }203 204 185 return *this; 205 186 } … … 207 188 hash_table_iterator operator++(int) 208 189 { 209 auto tmp_current = current_; 210 auto tmp_idx = idx_; 211 212 current_ = current_->next; 213 if (current_ == table_[idx_].head) 214 { 215 if (idx_ < max_idx_) 216 { 217 while (!table_[++idx_].head && idx_ < max_idx_) 218 { /* DUMMY BODY */ } 219 220 if (idx_ < max_idx_) 221 current_ = table_[idx_].head; 222 else 223 current_ = nullptr; 224 } 225 else 226 current_ = nullptr; 227 } 228 229 return hash_table_iterator{ 230 table_, tmp_idx, max_idx_, tmp_current 231 }; 190 auto tmp = *this; 191 ++(*this); 192 193 return tmp; 232 194 } 233 195 … … 319 281 hash_table_const_local_iterator operator++(int) 320 282 { 321 auto tmp = current_; 322 current_ = current_->next; 323 if (current_ == head_) 324 current_ = nullptr; 325 326 return hash_table_const_local_iterator{head_, tmp}; 283 auto tmp = *this; 284 ++(*this); 285 286 return tmp; 327 287 } 328 288 … … 397 357 hash_table_local_iterator operator++(int) 398 358 { 399 auto tmp = current_; 400 current_ = current_->next; 401 if (current_ == head_) 402 current_ = nullptr; 403 404 return hash_table_local_iterator{head_, tmp}; 359 auto tmp = *this; 360 ++(*this); 361 362 return tmp; 405 363 } 406 364
Note:
See TracChangeset
for help on using the changeset viewer.