aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Laskey <jlaskey@mac.com>2006-01-17 16:29:58 +0000
committerJim Laskey <jlaskey@mac.com>2006-01-17 16:29:58 +0000
commite3150024b46c528f1dd11d12a667d207d2da54ab (patch)
treeb4abe6f265758c2d40456bb339063b838da00bf8
parent57c517d30c18295f67287bc8e8577833737da828 (diff)
Reduce memory consumption and force (somewhat) access to entries via ID.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25393 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/UniqueVector.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/include/llvm/ADT/UniqueVector.h b/include/llvm/ADT/UniqueVector.h
index d00de388e2..87d905318e 100644
--- a/include/llvm/ADT/UniqueVector.h
+++ b/include/llvm/ADT/UniqueVector.h
@@ -18,17 +18,17 @@ namespace llvm {
//===----------------------------------------------------------------------===//
/// UniqueVector - This class produces a sequential ID number (base 1) for each
-/// unique entry that is added. This class also provides an ID ordered vector
-/// of the entries (indexed by ID - 1.) T is the type of entries in the vector.
-/// This class should have an implementation of operator== and of operator<.
+/// unique entry that is added. T is the type of entries in the vector. This
+/// class should have an implementation of operator== and of operator<.
+/// Entries can be fetched using operator[] with the entry ID.
template<class T> class UniqueVector {
private:
// Map - Used to handle the correspondence of entry to ID.
- typename std::map<T, unsigned> Map;
+ std::map<T, unsigned> Map;
// Vector - ID ordered vector of entries. Entries can be indexed by ID - 1.
//
- typename std::vector<T> Vector;
+ std::vector<const T *> Vector;
public:
/// insert - Append entry to the vector if it doesn't already exist. Returns
@@ -44,25 +44,25 @@ public:
unsigned ID = Vector.size() + 1;
// Insert in map.
- Map.insert(MI, std::make_pair(Entry, ID));
+ MI = Map.insert(MI, std::make_pair(Entry, ID));
// Insert in vector.
- Vector.push_back(Entry);
+ Vector.push_back(&MI->first);
return ID;
}
/// 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 { return *Vector[ID - 1]; }
/// size - Returns the number of entries in the vector.
///
size_t size() const { return Vector.size(); }
- /// getVector - Return the ID ordered vector of entries.
+ /// empty - Returns true if the vector is empty.
///
- const typename std::vector<T> &getVector() const { return Vector; }
+ bool empty() const { return Vector.empty(); }
};
} // End of namespace llvm