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
This commit is contained in:
Ted Kremenek 2008-07-11 22:43:07 +00:00
parent 499d7cf188
commit eca64f0980

View 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