Fold the useful features of alist and alist_node into ilist, and
[oota-llvm.git] / include / llvm / ADT / ImmutableMap.h
index de1c5875a32e6f59bde7042c97d6a998a696c125..bbf34c566d8bfaa8cff069e8c3e9af7b5c276609 100644 (file)
@@ -76,7 +76,8 @@ public:
   /// should use a Factory object to create maps instead of directly
   /// invoking the constructor, but there are cases where make this
   /// constructor public is useful.
-  explicit ImmutableMap(TreeTy* R) : Root(R) {}
+  explicit ImmutableMap(TreeTy* R) : Root(R) {}  
+  explicit ImmutableMap(const TreeTy* R) : Root(const_cast<TreeTy*>(R)) {}
   
   class Factory {
     typename TreeTy::Factory F;
@@ -84,6 +85,9 @@ public:
   public:
     Factory() {}
     
+    Factory(BumpPtrAllocator& Alloc)
+      : F(Alloc) {}
+    
     ImmutableMap GetEmptyMap() { return ImmutableMap(F.GetEmptyTree()); }
     
     ImmutableMap Add(ImmutableMap Old, key_type_ref K, data_type_ref D) {
@@ -173,39 +177,40 @@ public:
     friend class ImmutableMap;
 
   public:
-    inline value_type_ref operator*() const { return itr->getValue(); }
-    inline key_type_ref getKey() const { return itr->getValue().first; }
-    inline data_type_ref getData() const { return itr->getValue().second; }
+    value_type_ref operator*() const { return itr->getValue(); }
+    value_type*    operator->() const { return &itr->getValue(); }
+    
+    key_type_ref getKey() const { return itr->getValue().first; }
+    data_type_ref getData() const { return itr->getValue().second; }
     
-    inline iterator& operator++() { ++itr; return *this; }
-    inline iterator  operator++(int) { iterator tmp(*this); ++itr; return tmp; }
-    inline iterator& operator--() { --itr; return *this; }
-    inline iterator  operator--(int) { iterator tmp(*this); --itr; return tmp; }
-    inline bool operator==(const iterator& RHS) const { return RHS.itr == itr; }
-    inline bool operator!=(const iterator& RHS) const { return RHS.itr != itr; }        
+    
+    iterator& operator++() { ++itr; return *this; }
+    iterator  operator++(int) { iterator tmp(*this); ++itr; return tmp; }
+    iterator& operator--() { --itr; return *this; }
+    iterator  operator--(int) { iterator tmp(*this); --itr; return tmp; }
+    bool operator==(const iterator& RHS) const { return RHS.itr == itr; }
+    bool operator!=(const iterator& RHS) const { return RHS.itr != itr; }        
   };
   
   iterator begin() const { return iterator(Root); }
   iterator end() const { return iterator(); }  
   
-  TreeTy* SlimFind(key_type_ref K) const {
+  data_type* lookup(key_type_ref K) const {
     if (Root) {
       TreeTy* T = Root->find(K);
-      if (T) return T;
+      if (T) return &T->getValue().second;
     }
     
-    return NULL;
+    return 0;
   }
   
-  // FIXME: Add 'find' that returns an iterator instead of a TreeTy*.
-  
   //===--------------------------------------------------===//    
   // Utility methods.
   //===--------------------------------------------------===//  
   
   inline unsigned getHeight() const { return Root ? Root->getHeight() : 0; }
 
-  static inline void Profile(FoldingSetNodeID& ID, const ImmutableMap& M) { 
+  static inline void Profile(FoldingSetNodeID& ID, const ImmutableMap& M) {
     ID.AddPointer(M.Root);
   }