llvm.org GIT mirror llvm / 5501e56
Add default index functor (an identity functor). You could use a vector directly to get the same functionality but using a DenseMap makes the code more readable IMO. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16052 91177308-0d34-0410-b5e6-96231b3b80d8 Alkis Evlogimenos 15 years ago
3 changed file(s) with 54 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
2323
2424 namespace llvm {
2525
26 template
27 class DenseMap {
26 struct IdentityFunctor : std::unary_function {
27 unsigned operator()(unsigned Index) const {
28 return Index;
29 }
30 };
31
32 template
33 class DenseMap {
2834 typedef typename ToIndexT::argument_type IndexT;
2935 typedef std::vector StorageT;
3036 StorageT storage_;
3137 T nullVal_;
3238 ToIndexT toIndex_;
3339
34 public:
40 public:
3541 DenseMap() : nullVal_(T()) { }
3642
3743 explicit DenseMap(const T& val) : nullVal_(val) { }
3844
3945 typename StorageT::reference operator[](IndexT n) {
40 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
41 return storage_[toIndex_(n)];
46 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
47 return storage_[toIndex_(n)];
4248 }
4349
4450 typename StorageT::const_reference operator[](IndexT n) const {
45 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
46 return storage_[toIndex_(n)];
51 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
52 return storage_[toIndex_(n)];
4753 }
4854
4955 void clear() {
50 storage_.clear();
56 storage_.clear();
5157 }
5258
5359 void grow(IndexT n) {
54 unsigned NewSize = toIndex_(n) + 1;
55 if (NewSize > storage_.size())
56 storage_.resize(NewSize, nullVal_);
60 unsigned NewSize = toIndex_(n) + 1;
61 if (NewSize > storage_.size())
62 storage_.resize(NewSize, nullVal_);
5763 }
58 };
64 };
5965
6066 } // End llvm namespace
6167
2323
2424 namespace llvm {
2525
26 template
27 class DenseMap {
26 struct IdentityFunctor : std::unary_function {
27 unsigned operator()(unsigned Index) const {
28 return Index;
29 }
30 };
31
32 template
33 class DenseMap {
2834 typedef typename ToIndexT::argument_type IndexT;
2935 typedef std::vector StorageT;
3036 StorageT storage_;
3137 T nullVal_;
3238 ToIndexT toIndex_;
3339
34 public:
40 public:
3541 DenseMap() : nullVal_(T()) { }
3642
3743 explicit DenseMap(const T& val) : nullVal_(val) { }
3844
3945 typename StorageT::reference operator[](IndexT n) {
40 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
41 return storage_[toIndex_(n)];
46 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
47 return storage_[toIndex_(n)];
4248 }
4349
4450 typename StorageT::const_reference operator[](IndexT n) const {
45 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
46 return storage_[toIndex_(n)];
51 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
52 return storage_[toIndex_(n)];
4753 }
4854
4955 void clear() {
50 storage_.clear();
56 storage_.clear();
5157 }
5258
5359 void grow(IndexT n) {
54 unsigned NewSize = toIndex_(n) + 1;
55 if (NewSize > storage_.size())
56 storage_.resize(NewSize, nullVal_);
60 unsigned NewSize = toIndex_(n) + 1;
61 if (NewSize > storage_.size())
62 storage_.resize(NewSize, nullVal_);
5763 }
58 };
64 };
5965
6066 } // End llvm namespace
6167
2323
2424 namespace llvm {
2525
26 template
27 class DenseMap {
26 struct IdentityFunctor : std::unary_function {
27 unsigned operator()(unsigned Index) const {
28 return Index;
29 }
30 };
31
32 template
33 class DenseMap {
2834 typedef typename ToIndexT::argument_type IndexT;
2935 typedef std::vector StorageT;
3036 StorageT storage_;
3137 T nullVal_;
3238 ToIndexT toIndex_;
3339
34 public:
40 public:
3541 DenseMap() : nullVal_(T()) { }
3642
3743 explicit DenseMap(const T& val) : nullVal_(val) { }
3844
3945 typename StorageT::reference operator[](IndexT n) {
40 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
41 return storage_[toIndex_(n)];
46 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
47 return storage_[toIndex_(n)];
4248 }
4349
4450 typename StorageT::const_reference operator[](IndexT n) const {
45 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
46 return storage_[toIndex_(n)];
51 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
52 return storage_[toIndex_(n)];
4753 }
4854
4955 void clear() {
50 storage_.clear();
56 storage_.clear();
5157 }
5258
5359 void grow(IndexT n) {
54 unsigned NewSize = toIndex_(n) + 1;
55 if (NewSize > storage_.size())
56 storage_.resize(NewSize, nullVal_);
60 unsigned NewSize = toIndex_(n) + 1;
61 if (NewSize > storage_.size())
62 storage_.resize(NewSize, nullVal_);
5763 }
58 };
64 };
5965
6066 } // End llvm namespace
6167