Changeset 5af0bc9 in mainline
- Timestamp:
- 2018-07-05T21:41:21Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 921174c
- Parents:
- 79c9e0f
- git-author:
- Dzejrou <dzejrou@…> (2018-04-22 15:42:24)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/list.hpp
r79c9e0f r5af0bc9 87 87 prev = node; 88 88 } 89 90 void unlink() 91 { 92 prev->next = next; 93 next->prev = prev; 94 } 89 95 }; 90 96 … … 154 160 } 155 161 162 list_const_iterator operator-(difference_type n) const 163 { 164 /** 165 * Note: This operator is for internal purposes only, 166 * so we do not provide inverse operator or shortcut 167 * -= operator. 168 */ 169 auto tmp = current_; 170 171 for (difference_type i = 0; i < n; ++i) 172 tmp = tmp->prev; 173 174 return list_const_iterator{tmp}; 175 } 176 156 177 private: 157 178 list_node<value_type>* current_; … … 239 260 { 240 261 return list_const_iterator<T>{current_}; 262 } 263 264 list_iterator operator-(difference_type n) const 265 { 266 /** 267 * Note: This operator is for internal purposes only, 268 * so we do not provide inverse operator or shortcut 269 * -= operator. 270 */ 271 auto tmp = current_; 272 273 for (difference_type i = 0; i < n; ++i) 274 tmp = tmp->prev; 275 276 return list_iterator{tmp}; 241 277 } 242 278 … … 624 660 head_ = head_->prev; 625 661 626 return iterator{node->prev };662 return iterator{node->prev, head_}; 627 663 } 628 664 … … 658 694 } 659 695 660 return iterator{position.node()->next };696 return iterator{position.node()->next, head_}; 661 697 } 662 698 … … 669 705 { 670 706 auto node = position.node(); 707 708 if (node == head_) 709 { 710 if (size_ == 1) 711 { 712 delete head_; 713 head_ = nullptr; 714 size_ = 0; 715 716 return end(); 717 } 718 else 719 head_ = node->next; 720 } 721 722 auto next = node->next; 723 671 724 --size_; 672 725 673 if (node != get_last_()) 674 { 675 auto next = node->next; 676 auto prev = node->prev; 677 678 next->prev = prev; 679 prev->next = next; 680 681 delete node; 682 683 return iterator{next}; 684 } 685 else 686 { 687 auto prev = node->prev; 688 head_->prev = prev; 689 prev->next = head_; 690 691 delete node; 692 693 return end(); 694 } 726 node->unlink(); 727 delete node; 728 729 return iterator{next, head_}; 695 730 } 696 731 … … 709 744 while (first_node != next) 710 745 { 746 // TODO: test with head in the range 747 /* if (first_node == head_) */ 748 /* head_ = last.node()->next; */ 749 711 750 auto tmp = first_node; 712 751 first_node = first_node->next; … … 716 755 } 717 756 718 return iterator{next };757 return iterator{next, head_}; 719 758 } 720 759 … … 870 909 } 871 910 911 void remove(const value_type& val) 912 { 913 if (!head_) 914 return; 915 916 auto it = begin(); 917 while (it != end()) 918 { 919 if (*it == val) 920 it = erase(it); 921 else 922 ++it; 923 } 924 } 925 926 template<class Predicate> 927 void remove_if(Predicate pred) 928 { 929 if (!head_) 930 return; 931 932 auto it = begin(); 933 while (it != end()) 934 { 935 if (pred(*it)) 936 it = erase(it); 937 else 938 ++it; 939 } 940 } 941 942 void unique() 943 { 944 if (!head_) 945 return; 946 947 auto it = begin(); 948 ++it; 949 950 while (it != end()) 951 { 952 if (*it == *(it - 1)) 953 it = erase(it); 954 else 955 ++it; 956 } 957 } 958 959 template<class BinaryPredicate> 960 void unique(BinaryPredicate pred) 961 { 962 if (!head_) 963 return; 964 965 auto it = begin(); 966 ++it; 967 968 while (it != end()) 969 { 970 if (pred(*it, *(it - 1))) 971 it = erase(it); 972 else 973 ++it; 974 } 975 } 976 977 // TODO: make a generic base for algorithms like merge 978 // and quicksort that uses a swapper (the <algorithm> 979 // versions would use std::swap and list versions would 980 // use a swapper that swaps list nodes) 981 872 982 private: 873 983 allocator_type allocator_;
Note:
See TracChangeset
for help on using the changeset viewer.