Make some minor improvements to APInt:
[oota-llvm.git] / include / llvm / ADT / hash_map.in
index ca6098043961ee90ad400694153cef4581c9ac32..fe5c3939f52b0c98000bd384cdadb887de53d201 100644 (file)
@@ -24,7 +24,7 @@
 //  3.0.4       std      ext/hash_map
 //  3.1      __gnu_cxx   ext/hash_map
 //  HP aCC6     std      stdex/rw/hashm*ap.h
-//
+//  MS VC++    stdext      hash_map
 
 #undef HAVE_GNU_EXT_HASH_MAP
 #undef HAVE_STD_EXT_HASH_MAP
 #  define HASH_NAMESPACE std
 # endif
 
+// Support Microsoft VC++.
+#elif defined(_MSC_VER)
+# include <hash_map>
+# ifndef HASH_NAMESPACE
+#  define HASH_NAMESPACE stdext
+   using std::_Distance;
+# endif
+
 // Give a warning if we couldn't find it, instead of (or in addition to)
 // randomly doing something dumb.
 #else
 namespace HASH_NAMESPACE {
 
 template <class DataType> struct hash {
-       unsigned int operator()(const unsigned int& x) const {
-           return x;
-       }
+  unsigned int operator()(const unsigned int& x) const {
+      return x;
+  }
 };
 
 template <typename KeyType,
-         typename ValueType,
-         class _HashFcn = hash<KeyType>,
-         class _EqualKey = equal_to<KeyType>,
-         class _A = allocator <ValueType> >
-class hash_map : public rw_hashmap<KeyType, ValueType, class _HashFcn, class _EqualKey, class _A> {
+          typename ValueType,
+          class _HashFcn = hash<KeyType>,
+          class _EqualKey = equal_to<KeyType>,
+          class _A = allocator <ValueType> >
+class hash_map : public rw_hashmap<KeyType, ValueType, class _HashFcn, 
+                                   class _EqualKey, class _A> {
 };
 
 template <typename KeyType,
-         typename ValueType,
-         class _HashFcn = hash<KeyType>,
-         class _EqualKey = equal_to<KeyType>,
-         class _A = allocator <ValueType> >
-class hash_multimap : public rw_hashmultimap<KeyType, ValueType, class _HashFcn, class _EqualKey, class _A> {
+          typename ValueType,
+          class _HashFcn = hash<KeyType>,
+          class _EqualKey = equal_to<KeyType>,
+          class _A = allocator <ValueType> >
+class hash_multimap : public rw_hashmultimap<KeyType, ValueType, class _HashFcn,
+                                             class _EqualKey, class _A> {
 };
 
 } // end HASH_NAMESPACE;
 #endif
 
-using HASH_NAMESPACE::hash_map;
-using HASH_NAMESPACE::hash_multimap;
-using HASH_NAMESPACE::hash;
-
 // Include vector because ext/hash_map includes stl_vector.h and leaves
 // out specializations like stl_bvector.h, causing link conflicts.
 #include <vector>
 
+#ifdef _MSC_VER
+
+// GCC and VC++ have differing ways of implementing hash_maps.  As it's not
+// standardized, that's to be expected.  This adapter class allows VC++
+// hash_map to use GCC's hash classes.
+namespace stdext {
+  template<class Key> struct hash;
+  
+  // Provide a hash function for unsigned ints...
+  template<> struct hash<unsigned int> {
+    inline size_t operator()(unsigned int Val) const {
+      return Val;
+    }
+  };
+
+  template<class Key> class hash_compare<Key, std::less<Key> > {
+    std::less<Key> comp;
+  public:
+    enum { bucket_size = 4 };
+    enum { min_buckets = 8 };
+    hash_compare() {}
+    hash_compare(std::less<Key> pred) : comp(pred) {}
+    size_t operator()(const Key& key) const { return hash<Key>()(key); }
+    bool operator()(const Key& k1, const Key& k2) const { return comp(k1, k2); }
+  };
+}
+
+#endif
+
+using HASH_NAMESPACE::hash_map;
+using HASH_NAMESPACE::hash_multimap;
+using HASH_NAMESPACE::hash;
+
 #include "llvm/ADT/HashExtras.h"
 
 #endif