Changeset 369f5df 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:
- 7644d6e
- Parents:
- 647b756
- git-author:
- Dzejrou <dzejrou@…> (2018-04-30 19:50:44)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/internal/rbtree.hpp
r647b756 r369f5df 178 178 179 179 template<class... Args> 180 pair<iterator, bool> emplace(Args&&... args) 181 { 182 auto ret = Policy::emplace(*this, forward<Args>(args)...); 183 if (!ret.second) 184 return ret; 185 ++size_; 186 187 repair_after_insert_(ret.first.node()); 188 update_root_(ret.first.node()); 189 190 return ret; 191 } 192 193 pair<iterator, bool> insert(const value_type& val) 194 { 195 auto ret = Policy::insert(*this, val); 196 if (!ret.second) 197 return ret; 198 ++size_; 199 200 repair_after_insert_(ret.first.node()); 201 update_root_(ret.first.node()); 202 203 return ret; 204 } 205 206 pair<iterator, bool> insert(value_type&& val) 207 { 208 auto ret = Policy::insert(*this, forward<value_type>(val)); 209 if (!ret.second) 210 return ret; 211 ++size_; 212 213 repair_after_insert_(ret.first.node()); 214 update_root_(ret.first.node()); 215 216 return ret; 180 auto emplace(Args&&... args) 181 { 182 return Policy::emplace(*this, forward<Args>(args)...); 183 } 184 185 auto insert(const value_type& val) 186 { 187 return Policy::insert(*this, val); 188 } 189 190 auto insert(value_type&& val) 191 { 192 return Policy::insert(*this, forward<value_type>(val)); 217 193 } 218 194 … … 228 204 229 205 auto node = const_cast<node_type*>(it.node()); 230 ++it; 231 232 delete_node(node); 233 return iterator{const_cast<node_type*>(it.node()), it.end()}; 206 207 node = delete_node(node); 208 return iterator{const_cast<node_type*>(node), node == nullptr}; 234 209 } 235 210 … … 320 295 auto it2 = other.begin(); 321 296 297 // TODO: this doesn't compare values :/ 322 298 while (keys_equal(*it1++, *it2++)) 323 299 { /* DUMMY BODY */ } … … 358 334 } 359 335 360 void delete_node(node_type* node) 361 { 336 node_type* delete_node(const node_type* n) 337 { 338 auto node = const_cast<node_type*>(n); 362 339 if (!node) 363 return ;340 return nullptr; 364 341 365 342 --size_; 366 343 344 auto succ = node->successor(); 367 345 if (node->left && node->right) 368 346 { 369 node->swap( node->successor());370 371 // Node nowhas at most one child.372 delete_node( node);373 374 return ;347 node->swap(succ); 348 349 // Succ has at most one child. 350 delete_node(succ); 351 352 return node; 375 353 } 376 354 … … 379 357 { 380 358 // Simply remove the node. 359 // TODO: repair here too? 381 360 node->unlink(); 382 383 361 delete node; 384 362 } … … 389 367 if (node->is_left_child()) 390 368 child->parent->left = child; 391 else if (node->is_ left_child())369 else if (node->is_right_child()) 392 370 child->parent->right = child; 393 371 … … 395 373 repair_after_erase_(node, child); 396 374 update_root_(child); 397 } 375 376 delete node; 377 } 378 379 return succ; 398 380 } 399 381
Note:
See TracChangeset
for help on using the changeset viewer.