Add range insert method for DenseSet and define DenseMapInfo for chars.
authorChris Lattner <sabre@nondot.org>
Wed, 1 Apr 2009 19:50:49 +0000 (19:50 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 1 Apr 2009 19:50:49 +0000 (19:50 +0000)
Patch by Kevin Fan!

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

include/llvm/ADT/DenseMap.h
include/llvm/ADT/DenseSet.h

index ce0c006cf2b6606bf93008e6fde47e7dcb8463d9..cb951815f83ad47df57ded97f15192f1ef8fb0c0 100644 (file)
@@ -51,6 +51,17 @@ struct DenseMapInfo<T*> {
   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; }
index 953c67d53ebdf49b34c34f9f3f26217a7e86044d..ce7344bc1f99b3eab218817559d9f3300cf8a182 100644 (file)
@@ -90,6 +90,13 @@ public:
   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