diff options
author | Jim Laskey <jlaskey@mac.com> | 2006-01-26 20:09:35 +0000 |
---|---|---|
committer | Jim Laskey <jlaskey@mac.com> | 2006-01-26 20:09:35 +0000 |
commit | 32b5f41f15ebb9e3ddeef82f90d1e08f956a8dc7 (patch) | |
tree | c856b80acbae87b0c5474834cf67a5a38f8881ad | |
parent | ebbfb386a5ef43a5848edca55d8507bd5f6cee55 (diff) | |
download | bcm5719-llvm-32b5f41f15ebb9e3ddeef82f90d1e08f956a8dc7.tar.gz bcm5719-llvm-32b5f41f15ebb9e3ddeef82f90d1e08f956a8dc7.zip |
Add support to find existing entries.
llvm-svn: 25654
-rw-r--r-- | llvm/include/llvm/ADT/UniqueVector.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/UniqueVector.h b/llvm/include/llvm/ADT/UniqueVector.h index edb7d1a719a..e888678675e 100644 --- a/llvm/include/llvm/ADT/UniqueVector.h +++ b/llvm/include/llvm/ADT/UniqueVector.h @@ -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 |