[llvm-commits] CVS: llvm/include/llvm/ADT/UniqueVector.h
Jim Laskey
jlaskey at apple.com
Thu Jan 26 12:09:47 PST 2006
Changes in directory llvm/include/llvm/ADT:
UniqueVector.h updated: 1.4 -> 1.5
---
Log message:
Add support to find existing entries.
---
Diffs of the changes: (+20 -0)
UniqueVector.h | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+)
Index: llvm/include/llvm/ADT/UniqueVector.h
diff -u llvm/include/llvm/ADT/UniqueVector.h:1.4 llvm/include/llvm/ADT/UniqueVector.h:1.5
--- llvm/include/llvm/ADT/UniqueVector.h:1.4 Tue Jan 17 13:21:01 2006
+++ llvm/include/llvm/ADT/UniqueVector.h Thu Jan 26 14:09:35 2006
@@ -52,6 +52,19 @@
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 @@
/// 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
More information about the llvm-commits
mailing list