Changes in directory llvm/include/llvm/ADT:
DenseMap.h updated: 1.15 -> 1.16 --- Log message: add a version of insert that takes the key and value. --- Diffs of the changes: (+23 -8) DenseMap.h | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) Index: llvm/include/llvm/ADT/DenseMap.h diff -u llvm/include/llvm/ADT/DenseMap.h:1.15 llvm/include/llvm/ADT/DenseMap.h:1.16 --- llvm/include/llvm/ADT/DenseMap.h:1.15 Sat Feb 3 13:30:48 2007 +++ llvm/include/llvm/ADT/DenseMap.h Sat Feb 3 18:42:41 2007 @@ -111,6 +111,16 @@ return end(); } + bool insert(const std::pair<KeyT, ValueT> &KV) { + BucketT *TheBucket; + if (LookupBucketFor(KV.first, TheBucket)) + return false; // Already in map. + + // Otherwise, insert the new element. + InsertIntoBucket(KV.first, KV.second, TheBucket); + return true; + } + bool erase(const KeyT &Val) { BucketT *TheBucket; if (!LookupBucketFor(Val, TheBucket)) @@ -129,23 +139,28 @@ return true; } - ValueT &operator[](const KeyT &Val) { + ValueT &operator[](const KeyT &Key) { BucketT *TheBucket; - if (LookupBucketFor(Val, TheBucket)) + if (LookupBucketFor(Key, TheBucket)) return TheBucket->second; + return InsertIntoBucket(Key, ValueT(), TheBucket)->second; + } + +private: + BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value, + BucketT *TheBucket) { // If the load of the hash table is more than 3/4, grow it. if (NumEntries*4 >= NumBuckets*3) { this->grow(); - LookupBucketFor(Val, TheBucket); + LookupBucketFor(Key, TheBucket); } ++NumEntries; - TheBucket->first = Val; - new (&TheBucket->second) ValueT(); - return TheBucket->second; + TheBucket->first = Key; + new (&TheBucket->second) ValueT(Value); + return TheBucket; } - -private: + static unsigned getHashValue(const KeyT &Val) { return DenseMapKeyInfo<KeyT>::getHashValue(Val); } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits