1 //===-- llvm/ADT/hash_map - "Portable" wrapper around hash_map --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_ADT_HASH_MAP
18 #define LLVM_ADT_HASH_MAP
20 // Compiler Support Matrix
22 // Version Namespace Header File
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
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
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
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
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
52 # ifndef HASH_NAMESPACE
53 # define HASH_NAMESPACE std
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
66 // Support Microsoft VC++.
67 #elif defined(_MSC_VER)
69 # ifndef HASH_NAMESPACE
70 # define HASH_NAMESPACE stdext
74 // Give a warning if we couldn't find it, instead of (or in addition to)
75 // randomly doing something dumb.
77 # warning "Autoconfiguration failed to find the hash_map header file."
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 {
84 template <class DataType> struct hash {
85 unsigned int operator()(const unsigned int& x) const {
90 template <typename KeyType,
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> {
99 template <typename KeyType,
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> {
108 } // end HASH_NAMESPACE;
111 // Include vector because ext/hash_map includes stl_vector.h and leaves
112 // out specializations like stl_bvector.h, causing link conflicts.
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.
121 template<class Key> struct hash;
123 // Provide a hash function for unsigned ints...
124 template<> struct hash<unsigned int> {
125 inline size_t operator()(unsigned int Val) const {
130 template<class Key> class hash_compare<Key, std::less<Key> > {
133 enum { bucket_size = 4 };
134 enum { min_buckets = 8 };
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); }
144 using HASH_NAMESPACE::hash_map;
145 using HASH_NAMESPACE::hash_multimap;
146 using HASH_NAMESPACE::hash;
148 #include "llvm/ADT/HashExtras.h"