llvm.org GIT mirror llvm / 1829076
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 Chris Lattner 13 years ago
1 changed file(s) with 13 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
4040 bool empty() const { return Vector.empty(); }
4141 unsigned size() const { return Vector.size(); }
4242
43 iterator find(const T &V) const {
44 for (iterator I = begin(), E = end(); I != E; ++I)
45 if (*I == V)
46 return I;
47 return end();
48 }
49
4350 /// count - Return true if the element is in the set.
4451 unsigned count(const T &V) const {
4552 // Since the collection is small, just do a linear search.
46 for (iterator I = begin(), E = end(); I != E; ++I)
47 if (*I == V)
48 return 1;
49 return 0;
53 return find(V) != end();
5054 }
5155
5256 /// insert - Insert an element into the set if it isn't already there.
53 void insert(const T &V) {
54 if (count(V)) return; // Don't reinsert if it already exists.
57 std::pair insert(const T &V) {
58 iterator I = find(V);
59 if (I == end()) // Don't reinsert if it already exists.
60 return std::make_pair(I, false);
5561 Vector.push_back(V);
62 return std::make_pair(end()-1, true);
5663 }
5764
5865 void erase(const T &V) {