fe5c3939f52b0c98000bd384cdadb887de53d201
[oota-llvm.git] / include / llvm / ADT / hash_map.in
1 //===-- llvm/ADT/hash_map - "Portable" wrapper around hash_map --*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 // 
10 // This file provides a wrapper around the mysterious <hash_map> header file
11 // that seems to move around between GCC releases into and out of namespaces at
12 // will.  #including this header will cause hash_map to be available in the
13 // global namespace.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_ADT_HASH_MAP
18 #define LLVM_ADT_HASH_MAP
19
20 // Compiler Support Matrix
21 //
22 // Version   Namespace   Header File
23 //  2.95.x       ::        hash_map
24 //  3.0.4       std      ext/hash_map
25 //  3.1      __gnu_cxx   ext/hash_map
26 //  HP aCC6     std      stdex/rw/hashm*ap.h
27 //  MS VC++    stdext      hash_map
28
29 #undef HAVE_GNU_EXT_HASH_MAP
30 #undef HAVE_STD_EXT_HASH_MAP
31 #undef HAVE_GLOBAL_HASH_MAP
32 #undef HAVE_RW_STDEX_HASH_MAP_H
33
34 #if HAVE_GNU_EXT_HASH_MAP
35 // This is for GCC-3.1+ which puts hash in ext/hash_map
36 # include <ext/hash_map>
37 # ifndef HASH_NAMESPACE
38 #  define HASH_NAMESPACE __gnu_cxx
39 # endif
40
41 // GCC 3.0.x puts hash_map in <ext/hash_map> and in the std namespace.
42 #elif HAVE_STD_EXT_HASH_MAP
43 # include <ext/hash_map>
44 # ifndef HASH_NAMESPACE
45 #  define HASH_NAMESPACE std
46 # endif
47
48 // Older compilers such as GCC before version 3.0 do not keep
49 // extensions in the `ext' directory, and ignore the `std' namespace.
50 #elif HAVE_GLOBAL_HASH_MAP
51 # include <hash_map>
52 # ifndef HASH_NAMESPACE
53 #  define HASH_NAMESPACE std
54 # endif
55
56 // HP aCC doesn't include an SGI-like hash_map. For this platform (or
57 // any others using Rogue Wave Software's Tools.h++ library), we wrap
58 // around them in std::
59 #elif HAVE_RW_STDEX_HASH_MAP_H
60 # include <rw/stdex/hashmap.h>
61 # include <rw/stdex/hashmmap.h>
62 # ifndef HASH_NAMESPACE
63 #  define HASH_NAMESPACE std
64 # endif
65
66 // Support Microsoft VC++.
67 #elif defined(_MSC_VER)
68 # include <hash_map>
69 # ifndef HASH_NAMESPACE
70 #  define HASH_NAMESPACE stdext
71    using std::_Distance;
72 # endif
73
74 // Give a warning if we couldn't find it, instead of (or in addition to)
75 // randomly doing something dumb.
76 #else
77 # warning "Autoconfiguration failed to find the hash_map header file."
78 #endif
79
80 // we wrap Rogue Wave Tools.h++ rw_hashmap into something SGI-looking, here:
81 #ifdef HAVE_RW_STDEX_HASH_MAP_H
82 namespace HASH_NAMESPACE {
83
84 template <class DataType> struct hash {
85   unsigned int operator()(const unsigned int& x) const {
86       return x;
87   }
88 };
89
90 template <typename KeyType,
91           typename ValueType,
92           class _HashFcn = hash<KeyType>,
93           class _EqualKey = equal_to<KeyType>,
94           class _A = allocator <ValueType> >
95 class hash_map : public rw_hashmap<KeyType, ValueType, class _HashFcn, 
96                                    class _EqualKey, class _A> {
97 };
98
99 template <typename KeyType,
100           typename ValueType,
101           class _HashFcn = hash<KeyType>,
102           class _EqualKey = equal_to<KeyType>,
103           class _A = allocator <ValueType> >
104 class hash_multimap : public rw_hashmultimap<KeyType, ValueType, class _HashFcn,
105                                              class _EqualKey, class _A> {
106 };
107
108 } // end HASH_NAMESPACE;
109 #endif
110
111 // Include vector because ext/hash_map includes stl_vector.h and leaves
112 // out specializations like stl_bvector.h, causing link conflicts.
113 #include <vector>
114
115 #ifdef _MSC_VER
116
117 // GCC and VC++ have differing ways of implementing hash_maps.  As it's not
118 // standardized, that's to be expected.  This adapter class allows VC++
119 // hash_map to use GCC's hash classes.
120 namespace stdext {
121   template<class Key> struct hash;
122   
123   // Provide a hash function for unsigned ints...
124   template<> struct hash<unsigned int> {
125     inline size_t operator()(unsigned int Val) const {
126       return Val;
127     }
128   };
129
130   template<class Key> class hash_compare<Key, std::less<Key> > {
131     std::less<Key> comp;
132   public:
133     enum { bucket_size = 4 };
134     enum { min_buckets = 8 };
135     hash_compare() {}
136     hash_compare(std::less<Key> pred) : comp(pred) {}
137     size_t operator()(const Key& key) const { return hash<Key>()(key); }
138     bool operator()(const Key& k1, const Key& k2) const { return comp(k1, k2); }
139   };
140 }
141
142 #endif
143
144 using HASH_NAMESPACE::hash_map;
145 using HASH_NAMESPACE::hash_multimap;
146 using HASH_NAMESPACE::hash;
147
148 #include "llvm/ADT/HashExtras.h"
149
150 #endif