llvm.org GIT mirror llvm / f90fcaf
Add back() and pop_back() methods to SetVector Move clear to the end of the class Add assertions git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15203 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 15 years ago
2 changed file(s) with 56 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
1818
1919 #include
2020 #include
21 #include
2122
2223 namespace llvm {
2324
4344
4445 /// @brief Initialize a SetVector with a range of elements
4546 template
46 SetVector( It Start, It End ) {
47 SetVector(It Start, It End) {
4748 insert(Start, End);
48 }
49
50 /// @brief Completely clear the SetVector
51 void clear() {
52 set_.clear();
53 vector_.clear();
5449 }
5550
5651 /// @brief Determine if the SetVector is empty or not.
8378 return vector_.end();
8479 }
8580
81 /// @brief Return the last element of the SetVector.
82 const T &back() const {
83 assert(!empty() && "Cannot call back() on empty SetVector!");
84 return vector_.back();
85 }
86
8687 /// @brief Index into the SetVector.
8788 const_reference operator[](size_type n) const {
88 return vector_[n];
89 assert(n < vector_.size() && "SetVector access out of range!");
90 return vector_[n];
8991 }
9092
9193 /// @returns true iff the element was inserted into the SetVector.
9294 /// @brief Insert a new element into the SetVector.
93 bool insert( const value_type& X ) {
95 bool insert(const value_type &X) {
9496 bool result = set_.insert(X).second;
95 if ( result ) {
97 if (result)
9698 vector_.push_back(X);
97 }
9899 return result;
99100 }
100101
101102 /// @brief Insert a range of elements into the SetVector.
102103 template
103 void insert( It Start, It End ) {
104 void insert(It Start, It End) {
104105 for (; Start != End; ++Start)
105 if ( set_.insert(*Start).second )
106 if (set_.insert(*Start).second)
106107 vector_.push_back(*Start);
107108 }
108109
109110 /// @returns 0 if the element is not in the SetVector, 1 if it is.
110111 /// @brief Count the number of elements of a given key in the SetVector.
111 size_type count( const key_type& key ) const {
112 size_type count(const key_type &key) const {
112113 return set_.count(key);
114 }
115
116 /// @brief Completely clear the SetVector
117 void clear() {
118 set_.clear();
119 vector_.clear();
120 }
121
122 /// @brief Remove the last element of the SetVector.
123 void pop_back() {
124 assert(!empty() && "Cannot remove an element from an empty SetVector!");
125 set_.erase(back());
126 vector_.pop_back();
113127 }
114128
115129 private:
1818
1919 #include
2020 #include
21 #include
2122
2223 namespace llvm {
2324
4344
4445 /// @brief Initialize a SetVector with a range of elements
4546 template
46 SetVector( It Start, It End ) {
47 SetVector(It Start, It End) {
4748 insert(Start, End);
48 }
49
50 /// @brief Completely clear the SetVector
51 void clear() {
52 set_.clear();
53 vector_.clear();
5449 }
5550
5651 /// @brief Determine if the SetVector is empty or not.
8378 return vector_.end();
8479 }
8580
81 /// @brief Return the last element of the SetVector.
82 const T &back() const {
83 assert(!empty() && "Cannot call back() on empty SetVector!");
84 return vector_.back();
85 }
86
8687 /// @brief Index into the SetVector.
8788 const_reference operator[](size_type n) const {
88 return vector_[n];
89 assert(n < vector_.size() && "SetVector access out of range!");
90 return vector_[n];
8991 }
9092
9193 /// @returns true iff the element was inserted into the SetVector.
9294 /// @brief Insert a new element into the SetVector.
93 bool insert( const value_type& X ) {
95 bool insert(const value_type &X) {
9496 bool result = set_.insert(X).second;
95 if ( result ) {
97 if (result)
9698 vector_.push_back(X);
97 }
9899 return result;
99100 }
100101
101102 /// @brief Insert a range of elements into the SetVector.
102103 template
103 void insert( It Start, It End ) {
104 void insert(It Start, It End) {
104105 for (; Start != End; ++Start)
105 if ( set_.insert(*Start).second )
106 if (set_.insert(*Start).second)
106107 vector_.push_back(*Start);
107108 }
108109
109110 /// @returns 0 if the element is not in the SetVector, 1 if it is.
110111 /// @brief Count the number of elements of a given key in the SetVector.
111 size_type count( const key_type& key ) const {
112 size_type count(const key_type &key) const {
112113 return set_.count(key);
114 }
115
116 /// @brief Completely clear the SetVector
117 void clear() {
118 set_.clear();
119 vector_.clear();
120 }
121
122 /// @brief Remove the last element of the SetVector.
123 void pop_back() {
124 assert(!empty() && "Cannot remove an element from an empty SetVector!");
125 set_.erase(back());
126 vector_.pop_back();
113127 }
114128
115129 private: