Add support to find existing entries.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25654 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Laskey 2006-01-26 20:09:35 +00:00
parent 38f7373018
commit e4a359e43b

View 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