aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT
diff options
context:
space:
mode:
authorJim Laskey <jlaskey@mac.com>2006-01-26 20:09:35 +0000
committerJim Laskey <jlaskey@mac.com>2006-01-26 20:09:35 +0000
commite4a359e43b7af7db24482f1da3303c0bb7c9f425 (patch)
tree20faa077970860a818e7792a204ed10523359d98 /include/llvm/ADT
parent38f73730184c62529567e408fd0fbeeffe161a11 (diff)
downloadexternal_llvm-e4a359e43b7af7db24482f1da3303c0bb7c9f425.zip
external_llvm-e4a359e43b7af7db24482f1da3303c0bb7c9f425.tar.gz
external_llvm-e4a359e43b7af7db24482f1da3303c0bb7c9f425.tar.bz2
Add support to find existing entries.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25654 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r--include/llvm/ADT/UniqueVector.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/llvm/ADT/UniqueVector.h b/include/llvm/ADT/UniqueVector.h
index edb7d1a..e888678 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