Changeset 21d97e8 in mainline for uspace/lib/cpp/include/internal/rbtree_node.hpp
- Timestamp:
- 2018-07-05T21:41:23Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0fe0f32
- Parents:
- 5608106c
- git-author:
- Dzejrou <dzejrou@…> (2018-05-14 17:03:57)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/internal/rbtree_node.hpp
r5608106c r21d97e8 46 46 { 47 47 if (node && node->parent()) 48 return node->parent ->parent();48 return node->parent()->parent(); 49 49 else 50 50 return nullptr; … … 55 55 if (node && node->parent()) 56 56 { 57 if (node == node->parent ->left())58 return node->parent ->right();59 else 60 return node->parent ->left();57 if (node == node->parent()->left()) 58 return node->parent()->right(); 59 else 60 return node->parent()->left(); 61 61 } 62 62 else … … 573 573 const rbtree_multi_node* predecessor() const 574 574 { 575 return utils::predecessor(this); 575 if (this != first_) 576 { 577 auto tmp = first_; 578 while (tmp->next_ != this) 579 tmp = tmp->next_; 580 581 return tmp; 582 } 583 else 584 { 585 auto tmp = utils::predecessor(this); 586 587 /** 588 * If tmp was duplicate, we got a pointer 589 * to the first node in the list. So we need 590 * to move to the end. 591 */ 592 while (tmp->next_ != nullptr) 593 tmp = tmp->next_; 594 595 return tmp; 596 } 576 597 } 577 598 … … 591 612 } 592 613 593 rbtree_multi_node<T>* get_node_for_deletion() 594 { 614 rbtree_multi_node* get_node_for_deletion() 615 { 616 /** 617 * To make sure we delete nodes in 618 * the order of their insertion 619 * (not required, but sensical), we 620 * update then list and return this 621 * for deletion. 622 */ 595 623 if (next_) 596 624 { 597 auto tmp = next_; 598 while (tmp && tmp->next_ != this) 625 // Make next the new this. 626 next_->first_ = next_; 627 if (is_left_child()) 628 parent_->left_ = next_; 629 else if (is_right_child()) 630 parent_->right_ = next_; 631 632 if (left_) 633 left_->parent_ = next_; 634 if (right_) 635 right_->parent_ = next_; 636 637 /** 638 * Update the first_ pointer 639 * of the rest of the list. 640 */ 641 auto tmp = next_->next_; 642 while (tmp) 643 { 644 tmp->first_ = next_; 599 645 tmp = tmp->next_; 600 601 return tmp; // This will get deleted. 646 } 647 648 /** 649 * Otherwise destructor could 650 * destroy them. 651 */ 652 parent_ = nullptr; 653 left_ = nullptr; 654 right_ = nullptr; 655 next_ = nullptr; 656 first_ = nullptr; 657 658 return this; // This will get deleted. 602 659 } 603 660 else … … 608 665 { 609 666 if (is_left_child()) 610 parent ->left_ = nullptr;667 parent_->left_ = nullptr; 611 668 else if (is_right_child()) 612 parent ->right_ = nullptr;669 parent_->right_ = nullptr; 613 670 } 614 671
Note:
See TracChangeset
for help on using the changeset viewer.