llvm.org GIT mirror llvm / 28f7227
add a version of insert that takes the key and value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33856 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
1 changed file(s) with 25 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
110110 return end();
111111 }
112112
113 bool insert(const std::pair &KV) {
114 BucketT *TheBucket;
115 if (LookupBucketFor(KV.first, TheBucket))
116 return false; // Already in map.
117
118 // Otherwise, insert the new element.
119 InsertIntoBucket(KV.first, KV.second, TheBucket);
120 return true;
121 }
122
113123 bool erase(const KeyT &Val) {
114124 BucketT *TheBucket;
115125 if (!LookupBucketFor(Val, TheBucket))
128138 return true;
129139 }
130140
131 ValueT &operator[](const KeyT &Val) {
132 BucketT *TheBucket;
133 if (LookupBucketFor(Val, TheBucket))
141 ValueT &operator[](const KeyT &Key) {
142 BucketT *TheBucket;
143 if (LookupBucketFor(Key, TheBucket))
134144 return TheBucket->second;
135145
146 return InsertIntoBucket(Key, ValueT(), TheBucket)->second;
147 }
148
149 private:
150 BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value,
151 BucketT *TheBucket) {
136152 // If the load of the hash table is more than 3/4, grow it.
137153 if (NumEntries*4 >= NumBuckets*3) {
138154 this->grow();
139 LookupBucketFor(Val, TheBucket);
155 LookupBucketFor(Key, TheBucket);
140156 }
141157 ++NumEntries;
142 TheBucket->first = Val;
143 new (&TheBucket->second) ValueT();
144 return TheBucket->second;
145 }
146
147 private:
158 TheBucket->first = Key;
159 new (&TheBucket->second) ValueT(Value);
160 return TheBucket;
161 }
162
148163 static unsigned getHashValue(const KeyT &Val) {
149164 return DenseMapKeyInfo::getHashValue(Val);
150165 }