[llvm-commits] CVS: llvm/include/Support/SetVector.h
Chris Lattner
lattner at cs.uiuc.edu
Sun Jul 25 04:07:17 PDT 2004
Changes in directory llvm/include/Support:
SetVector.h updated: 1.3 -> 1.4
---
Log message:
Add back() and pop_back() methods to SetVector
Move clear to the end of the class
Add assertions
---
Diffs of the changes: (+28 -14)
Index: llvm/include/Support/SetVector.h
diff -u llvm/include/Support/SetVector.h:1.3 llvm/include/Support/SetVector.h:1.4
--- llvm/include/Support/SetVector.h:1.3 Thu Jul 15 03:18:31 2004
+++ llvm/include/Support/SetVector.h Sun Jul 25 06:07:02 2004
@@ -19,6 +19,7 @@
#include <set>
#include <vector>
+#include <cassert>
namespace llvm {
@@ -44,16 +45,10 @@
/// @brief Initialize a SetVector with a range of elements
template<typename It>
- SetVector( It Start, It End ) {
+ SetVector(It Start, It End) {
insert(Start, End);
}
- /// @brief Completely clear the SetVector
- void clear() {
- set_.clear();
- vector_.clear();
- }
-
/// @brief Determine if the SetVector is empty or not.
bool empty() const {
return vector_.empty();
@@ -84,35 +79,54 @@
return vector_.end();
}
+ /// @brief Return the last element of the SetVector.
+ const T &back() const {
+ assert(!empty() && "Cannot call back() on empty SetVector!");
+ return vector_.back();
+ }
+
/// @brief Index into the SetVector.
const_reference operator[](size_type n) const {
- return vector_[n];
+ assert(n < vector_.size() && "SetVector access out of range!");
+ return vector_[n];
}
/// @returns true iff the element was inserted into the SetVector.
/// @brief Insert a new element into the SetVector.
- bool insert( const value_type& X ) {
+ bool insert(const value_type &X) {
bool result = set_.insert(X).second;
- if ( result ) {
+ if (result)
vector_.push_back(X);
- }
return result;
}
/// @brief Insert a range of elements into the SetVector.
template<typename It>
- void insert( It Start, It End ) {
+ void insert(It Start, It End) {
for (; Start != End; ++Start)
- if ( set_.insert(*Start).second )
+ if (set_.insert(*Start).second)
vector_.push_back(*Start);
}
/// @returns 0 if the element is not in the SetVector, 1 if it is.
/// @brief Count the number of elements of a given key in the SetVector.
- size_type count( const key_type& key ) const {
+ size_type count(const key_type &key) const {
return set_.count(key);
}
+ /// @brief Completely clear the SetVector
+ void clear() {
+ set_.clear();
+ vector_.clear();
+ }
+
+ /// @brief Remove the last element of the SetVector.
+ void pop_back() {
+ assert(!empty() && "Cannot remove an element from an empty SetVector!");
+ set_.erase(back());
+ vector_.pop_back();
+ }
+
private:
set_type set_; ///< The set.
vector_type vector_; ///< The vector.
More information about the llvm-commits
mailing list