mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
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
This commit is contained in:
parent
5a0a1c2cba
commit
f90fcaf572
@ -19,6 +19,7 @@
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -44,16 +45,10 @@ public:
|
||||
|
||||
/// @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 @@ public:
|
||||
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.
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -44,16 +45,10 @@ public:
|
||||
|
||||
/// @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 @@ public:
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user