[LLVMdev] Patches: Range insertion for DenseSet; definition of DenseMapInfo<char>

Kevin Fan kevin.fan at gmail.com
Wed Apr 1 11:54:43 PDT 2009


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; }



More information about the llvm-dev mailing list