diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-07-11 22:43:07 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-07-11 22:43:07 +0000 |
commit | eca64f0980e3f686a36007c53272780119635337 (patch) | |
tree | 58cbceb1d7c55db722fcc9ec2734bf1366fce54f | |
parent | 499d7cf188d48e7f709d07212bbd367198a1569d (diff) | |
download | external_llvm-eca64f0980e3f686a36007c53272780119635337.zip external_llvm-eca64f0980e3f686a36007c53272780119635337.tar.gz external_llvm-eca64f0980e3f686a36007c53272780119635337.tar.bz2 |
Minor tweaks to the ImmutableList iterator interface.
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
-rw-r--r-- | include/llvm/ADT/ImmutableList.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/include/llvm/ADT/ImmutableList.h b/include/llvm/ADT/ImmutableList.h index 2219edd..dd88023 100644 --- a/include/llvm/ADT/ImmutableList.h +++ b/include/llvm/ADT/ImmutableList.h @@ -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 |