Give SetVector range support

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14855 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-07-15 08:18:31 +00:00
parent 69e5845a81
commit 5e87754250
2 changed files with 34 additions and 2 deletions

View File

@ -28,7 +28,6 @@ namespace llvm {
/// @breif A vector that has set insertion semantics.
template <typename T>
class SetVector {
public:
typedef T value_type;
typedef T key_type;
@ -40,6 +39,15 @@ public:
typedef typename vector_type::const_iterator const_iterator;
typedef typename vector_type::size_type size_type;
/// @brief Construct an empty SetVector
SetVector() {}
/// @brief Initialize a SetVector with a range of elements
template<typename It>
SetVector( It Start, It End ) {
insert(Start, End);
}
/// @brief Completely clear the SetVector
void clear() {
set_.clear();
@ -91,6 +99,14 @@ public:
return result;
}
/// @brief Insert a range of elements into the SetVector.
template<typename It>
void insert( It Start, It End ) {
for (; Start != End; ++Start)
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 {

View File

@ -28,7 +28,6 @@ namespace llvm {
/// @breif A vector that has set insertion semantics.
template <typename T>
class SetVector {
public:
typedef T value_type;
typedef T key_type;
@ -40,6 +39,15 @@ public:
typedef typename vector_type::const_iterator const_iterator;
typedef typename vector_type::size_type size_type;
/// @brief Construct an empty SetVector
SetVector() {}
/// @brief Initialize a SetVector with a range of elements
template<typename It>
SetVector( It Start, It End ) {
insert(Start, End);
}
/// @brief Completely clear the SetVector
void clear() {
set_.clear();
@ -91,6 +99,14 @@ public:
return result;
}
/// @brief Insert a range of elements into the SetVector.
template<typename It>
void insert( It Start, It End ) {
for (; Start != End; ++Start)
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 {