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 | e4a359e43b7af7db24482f1da3303c0bb7c9f425 (patch) | |
tree | 20faa077970860a818e7792a204ed10523359d98 | |
parent | 38f73730184c62529567e408fd0fbeeffe161a11 (diff) |
Add support to find existing entries.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25654 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/UniqueVector.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/llvm/ADT/UniqueVector.h b/include/llvm/ADT/UniqueVector.h index edb7d1a719..e888678675 100644 --- a/include/llvm/ADT/UniqueVector.h +++ b/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 |