diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-02-05 23:24:48 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-02-05 23:24:48 +0000 |
| commit | de20c42da53b94ae26be4eba8f3f0150c33e1401 (patch) | |
| tree | 4f73e72f325fccbd066ad3e2b2fe018a25bb3849 | |
| parent | 3d5c1e3fa76e450fa5a73f8aafc0cacdbf4abec6 (diff) | |
| download | bcm5719-llvm-de20c42da53b94ae26be4eba8f3f0150c33e1401.tar.gz bcm5719-llvm-de20c42da53b94ae26be4eba8f3f0150c33e1401.zip | |
Simplify this a bit, add an assertion
llvm-svn: 33936
| -rw-r--r-- | llvm/include/llvm/ADT/UniqueVector.h | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/llvm/include/llvm/ADT/UniqueVector.h b/llvm/include/llvm/ADT/UniqueVector.h index df9e1e5b2d6..8f0e686bf85 100644 --- a/llvm/include/llvm/ADT/UniqueVector.h +++ b/llvm/include/llvm/ADT/UniqueVector.h @@ -27,28 +27,24 @@ private: // Vector - ID ordered vector of entries. Entries can be indexed by ID - 1. // - std::vector<const T *> Vector; + std::vector<T> Vector; public: /// insert - Append entry to the vector if it doesn't already exist. Returns /// the entry's index + 1 to be used as a unique ID. unsigned insert(const T &Entry) { // Check if the entry is already in the map. - typename std::map<T, unsigned>::iterator MI = Map.lower_bound(Entry); + unsigned &Val = Map[Entry]; // See if entry exists, if so return prior ID. - if (MI != Map.end() && MI->first == Entry) return MI->second; + if (Val) return Val; // Compute ID for entry. - unsigned ID = Vector.size() + 1; - - // Insert in map. - MI = Map.insert(MI, std::make_pair(Entry, ID)); + Val = Vector.size() + 1; // Insert in vector. - Vector.push_back(&MI->first); - - return ID; + Vector.push_back(Entry); + return Val; } /// idFor - return the ID for an existing entry. Returns 0 if the entry is @@ -66,7 +62,10 @@ public: /// operator[] - Returns a reference to the entry with the specified ID. /// - const T &operator[](unsigned ID) const { return *Vector[ID - 1]; } + const T &operator[](unsigned ID) const { + assert(ID-1 < size() && "ID is 0 or out of range!"); + return Vector[ID - 1]; + } /// size - Returns the number of entries in the vector. /// |

