Minor tweaks to the ImmutableList iterator interface.
authorTed Kremenek <kremenek@apple.com>
Fri, 11 Jul 2008 22:43:07 +0000 (22:43 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 11 Jul 2008 22:43:07 +0000 (22:43 +0000)
Added partial specialization of DenseMapInfo<T> for ImmutableList.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53485 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/ImmutableList.h

index 2219edd90206be663188e68d49ef8151a49eff51..dd88023fd1f90ba832d54632798ade0ca517224c 100644 (file)
@@ -73,7 +73,7 @@ public:
   // This constructor should normally only be called by ImmutableListFactory<T>.
   // There may be cases, however, when one needs to extract the internal pointer
   // and reconstruct a list object from that pointer.
-  ImmutableList(ImmutableListImpl<T>* x) : X(x) {}
+  ImmutableList(ImmutableListImpl<T>* x = 0) : X(x) {}
 
   ImmutableListImpl<T>* getInternalPointer() const {
     return X;
@@ -88,7 +88,8 @@ public:
     iterator& operator++() { L = L->getTail(); return *this; }
     bool operator==(const iterator& I) const { return L == I.L; }
     bool operator!=(const iterator& I) const { return L != I.L; }
-    ImmutableList operator*() const { return L; }
+    const value_type& operator*() const { return L->getHead(); }    
+    ImmutableList getList() const { return L; }    
   };
 
   /// begin - Returns an iterator referring to the head of the list, or
@@ -186,6 +187,29 @@ public:
   }
 };
   
+//===----------------------------------------------------------------------===//  
+// Partially-specialized Traits.
+//===----------------------------------------------------------------------===//  
+  
+template<typename T> struct DenseMapInfo;
+template<typename T> struct DenseMapInfo<ImmutableList<T> > {
+  static inline ImmutableList<T> getEmptyKey() {
+    return reinterpret_cast<ImmutableListImpl<T>*>(-1);
+  }
+  static inline ImmutableList<T> getTombstoneKey() {
+    return reinterpret_cast<ImmutableListImpl<T>*>(-2);
+  }
+  static unsigned getHashValue(ImmutableList<T> X) {
+    uintptr_t PtrVal = reinterpret_cast<uintptr_t>(X.getInternalPointer());
+    return (unsigned((uintptr_t)PtrVal) >> 4) ^ 
+           (unsigned((uintptr_t)PtrVal) >> 9);
+  }
+  static bool isEqual(ImmutableList<T> X1, ImmutableList<T> X2) {
+    return X1 == X2;
+  }
+  static bool isPod() { return true; }
+};
+  
 } // end llvm namespace
 
 #endif