Added iterator and profiling (i.e. FoldingSetNodeID) support to ImmutableMap.
[oota-llvm.git] / include / llvm / ADT / DenseMap.h
index 91f00f99fe345febaebb41d8aac110138a1bf203..fdfb3294ea3d2553524aafca9e51b893228029e3 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -63,6 +63,8 @@ class DenseMap {
   unsigned NumEntries;
   unsigned NumTombstones;
 public:
+  typedef BucketT value_type;
+  
   DenseMap(const DenseMap& other) {
     NumBuckets = 0;
     CopyFrom(other);
@@ -174,13 +176,17 @@ public:
     ++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) {