Add support to find existing entries.
authorJim Laskey <jlaskey@mac.com>
Thu, 26 Jan 2006 20:09:35 +0000 (20:09 +0000)
committerJim Laskey <jlaskey@mac.com>
Thu, 26 Jan 2006 20:09:35 +0000 (20:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25654 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/UniqueVector.h

index edb7d1a719ab5cf726d81a92f958f2c44aaafc64..e888678675eff4a7ae4c2ea3e875046cb4a6f505 100644 (file)
@@ -52,6 +52,19 @@ public:
     return ID;
   }
   
+  /// idFor - return the ID for an existing entry.  Returns 0 if the entry is
+  /// not found.
+  unsigned idFor(const T &Entry) const {
+    // Search for entry in the map.
+    typename std::map<T, unsigned>::iterator MI = Map.lower_bound(Entry);
+    
+    // See if entry exists, if so return ID.
+    if (MI != Map.end() && MI->first == Entry) return MI->second;
+    
+    // No luck.
+    return 0;
+  }
+
   /// operator[] - Returns a reference to the entry with the specified ID.
   ///
   const T &operator[](unsigned ID) const { return *Vector[ID - 1]; }
@@ -63,6 +76,13 @@ public:
   /// empty - Returns true if the vector is empty.
   ///
   bool empty() const { return Vector.empty(); }
+  
+  /// reset - Clears all the entries.
+  ///
+  void reset() {
+    Map.clear();
+    Vector.resize(0, 0);
+  }
 };
 
 } // End of namespace llvm