Kevin Fan
2009-Apr-01 18:54 UTC
[LLVMdev] Patches: Range insertion for DenseSet; definition of DenseMapInfo<char>
Here are two minor patches. The first adds an insert method to DenseSet that takes two iterators representing the beginning and ending of a range of items to insert. I lifted the code verbatim from DenseMap.h. The second patch defines DenseMapInfo for chars. This is useful because DenseSet is implemented as a DenseMap of (Type, char), so anyone who uses DenseSet has to define DenseMapInfo for char. Let me know if this definition should go in some place other than DenseMap.h. Thanks! Kevin Fan Index: include/llvm/ADT/DenseSet.h ==================================================================--- include/llvm/ADT/DenseSet.h (revision 68214) +++ include/llvm/ADT/DenseSet.h (working copy) @@ -90,6 +90,13 @@ std::pair<iterator, bool> insert(const ValueT &V) { return TheMap.insert(std::make_pair(V, 0)); } + + // Range insertion of values. + template<typename InputIt> + void insert(InputIt I, InputIt E) { + for (; I != E; ++I) + insert(*I); + } }; } // end namespace llvm Index: include/llvm/ADT/DenseMap.h ==================================================================--- include/llvm/ADT/DenseMap.h (revision 68214) +++ include/llvm/ADT/DenseMap.h (working copy) @@ -51,6 +51,17 @@ static bool isPod() { return true; } }; +// Provide DenseMapInfo for chars. +template<> struct DenseMapInfo<char> { + static inline char getEmptyKey() { return ~0; } + static inline char getTombstoneKey() { return ~0 - 1; } + static unsigned getHashValue(const char& Val) { return Val * 37; } + static bool isPod() { return true; } + static bool isEqual(const char& LHS, const char& RHS) { + return LHS == RHS; + } +}; + // Provide DenseMapInfo for unsigned ints. template<> struct DenseMapInfo<unsigned> { static inline unsigned getEmptyKey() { return ~0; }
Chris Lattner
2009-Apr-01 19:51 UTC
[LLVMdev] Patches: Range insertion for DenseSet; definition of DenseMapInfo<char>
On Apr 1, 2009, at 11:54 AM, Kevin Fan wrote:> Here are two minor patches. The first adds an insert method to > DenseSet that takes two iterators representing the beginning and > ending of a range of items to insert. I lifted the code verbatim from > DenseMap.h. > The second patch defines DenseMapInfo for chars. This is useful > because DenseSet is implemented as a DenseMap of (Type, char), so > anyone who uses DenseSet has to define DenseMapInfo for char. Let me > know if this definition should go in some place other than DenseMap.h.Looks great, applied: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090330/075951.html For future reference, we greatly appreciate patches sent in as attachments instead of inline, this makes it easier to apply. Thanks for the patch! -Chris