[llvm-commits] CVS: llvm/include/llvm/ADT/SmallSet.h

Chris Lattner sabre at nondot.org
Mon Jan 22 17:16:35 PST 2007



Changes in directory llvm/include/llvm/ADT:

SmallSet.h updated: 1.1 -> 1.2
---
Log message:

make the SmallSet interface more std::set-like


---
Diffs of the changes:  (+13 -6)

 SmallSet.h |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)


Index: llvm/include/llvm/ADT/SmallSet.h
diff -u llvm/include/llvm/ADT/SmallSet.h:1.1 llvm/include/llvm/ADT/SmallSet.h:1.2
--- llvm/include/llvm/ADT/SmallSet.h:1.1	Mon Jan 22 18:59:15 2007
+++ llvm/include/llvm/ADT/SmallSet.h	Mon Jan 22 19:16:19 2007
@@ -41,19 +41,26 @@
   bool empty() const { return Vector.empty(); }
   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.
   unsigned count(const T &V) const {
     // Since the collection is small, just do a linear search.
-    for (iterator I = begin(), E = end(); I != E; ++I)
-      if (*I == V)
-        return 1;
-    return 0;
+    return find(V) != end();
   }
   
   /// insert - Insert an element into the set if it isn't already there.
-  void insert(const T &V) {
-    if (count(V)) return;   // Don't reinsert if it already exists.
+  std::pair<iterator,bool> insert(const T &V) {
+    iterator I = find(V);
+    if (I == end())    // Don't reinsert if it already exists.
+      return std::make_pair(I, false);
     Vector.push_back(V);
+    return std::make_pair(end()-1, true);
   }
   
   void erase(const T &V) {






More information about the llvm-commits mailing list