[llvm-commits] [llvm] r43594 - /llvm/trunk/include/llvm/ADT/DenseMap.h

Ted Kremenek kremenek at apple.com
Wed Oct 31 17:54:57 PDT 2007


Author: kremenek
Date: Wed Oct 31 19:54:57 2007
New Revision: 43594

URL: http://llvm.org/viewvc/llvm-project?rev=43594&view=rev
Log:
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).

Modified:
    llvm/trunk/include/llvm/ADT/DenseMap.h

Modified: llvm/trunk/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=43594&r1=43593&r2=43594&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Wed Oct 31 19:54:57 2007
@@ -63,6 +63,8 @@
   unsigned NumEntries;
   unsigned NumTombstones;
 public:
+  typedef BucketT value_type;
+  
   DenseMap(const DenseMap& other) {
     NumBuckets = 0;
     CopyFrom(other);
@@ -174,13 +176,17 @@
     ++NumTombstones;
     return true;
   }
-  
-  ValueT &operator[](const KeyT &Key) {
+
+  value_type& FindAndConstruct(const KeyT &Key) {
     BucketT *TheBucket;
     if (LookupBucketFor(Key, TheBucket))
-      return TheBucket->second;
-
-    return InsertIntoBucket(Key, ValueT(), TheBucket)->second;
+      return *TheBucket;
+    
+    return *InsertIntoBucket(Key, ValueT(), TheBucket);
+  }
+  
+  ValueT &operator[](const KeyT &Key) {
+    return FindAndConstruct(Key).second;
   }
   
   DenseMap& operator=(const DenseMap& other) {





More information about the llvm-commits mailing list