llvm.org GIT mirror llvm / aef806e
Added typedef "value_type" to DenseMap (similar typedef appears in std::map). Added method FindAndConstruct() to DenseMap, which does the same thing as operator[], except that it refers value_type& (a reference to both the key and mapped data pair). This method is useful for clients that wish to access the stored key value, as opposed to the key used to do the actual lookup (these need not always be the same). Redefined operator[] to use FindAndConstruct() (same logic). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43594 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 12 years ago
1 changed file(s) with 11 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
6262 unsigned NumEntries;
6363 unsigned NumTombstones;
6464 public:
65 typedef BucketT value_type;
66
6567 DenseMap(const DenseMap& other) {
6668 NumBuckets = 0;
6769 CopyFrom(other);
173175 ++NumTombstones;
174176 return true;
175177 }
178
179 value_type& FindAndConstruct(const KeyT &Key) {
180 BucketT *TheBucket;
181 if (LookupBucketFor(Key, TheBucket))
182 return *TheBucket;
183
184 return *InsertIntoBucket(Key, ValueT(), TheBucket);
185 }
176186
177187 ValueT &operator[](const KeyT &Key) {
178 BucketT *TheBucket;
179 if (LookupBucketFor(Key, TheBucket))
180 return TheBucket->second;
181
182 return InsertIntoBucket(Key, ValueT(), TheBucket)->second;
188 return FindAndConstruct(Key).second;
183189 }
184190
185191 DenseMap& operator=(const DenseMap& other) {