mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-10 04:33:40 +00:00
make the SmallSet interface more std::set-like
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33458 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
08a4d5a343
commit
182907645c
@ -41,19 +41,26 @@ public:
|
|||||||
bool empty() const { return Vector.empty(); }
|
bool empty() const { return Vector.empty(); }
|
||||||
unsigned size() const { return Vector.size(); }
|
unsigned size() const { return Vector.size(); }
|
||||||
|
|
||||||
|
iterator find(const T &V) const {
|
||||||
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
||||||
|
if (*I == V)
|
||||||
|
return I;
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
/// count - Return true if the element is in the set.
|
/// count - Return true if the element is in the set.
|
||||||
unsigned count(const T &V) const {
|
unsigned count(const T &V) const {
|
||||||
// Since the collection is small, just do a linear search.
|
// Since the collection is small, just do a linear search.
|
||||||
for (iterator I = begin(), E = end(); I != E; ++I)
|
return find(V) != end();
|
||||||
if (*I == V)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// insert - Insert an element into the set if it isn't already there.
|
/// insert - Insert an element into the set if it isn't already there.
|
||||||
void insert(const T &V) {
|
std::pair<iterator,bool> insert(const T &V) {
|
||||||
if (count(V)) return; // Don't reinsert if it already exists.
|
iterator I = find(V);
|
||||||
|
if (I == end()) // Don't reinsert if it already exists.
|
||||||
|
return std::make_pair(I, false);
|
||||||
Vector.push_back(V);
|
Vector.push_back(V);
|
||||||
|
return std::make_pair(end()-1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(const T &V) {
|
void erase(const T &V) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user