LLVM API Documentation

hash_map.h

Go to the documentation of this file.
00001 /* include/llvm/ADT/hash_map.h.  Generated from hash_map.h.in by configure.  */
00002 //==-- llvm/ADT/hash_map.h - "Portable" wrapper around hash_map --*- C++ -*-==//
00003 // 
00004 //                     The LLVM Compiler Infrastructure
00005 //
00006 // This file is distributed under the University of Illinois Open Source
00007 // License. See LICENSE.TXT for details.
00008 // 
00009 //===----------------------------------------------------------------------===//
00010 // 
00011 // This file provides a wrapper around the mysterious <hash_map> header file
00012 // that seems to move around between GCC releases into and out of namespaces at
00013 // will.  #including this header will cause hash_map to be available in the
00014 // global namespace.
00015 //
00016 //===----------------------------------------------------------------------===//
00017 
00018 #ifndef LLVM_ADT_HASH_MAP_H
00019 #define LLVM_ADT_HASH_MAP_H
00020 
00021 // Compiler Support Matrix
00022 //
00023 // Version   Namespace   Header File
00024 //  2.95.x       ::        hash_map
00025 //  3.0.4       std      ext/hash_map
00026 //  3.1      __gnu_cxx   ext/hash_map
00027 //  HP aCC6     std      stdex/rw/hashm*ap.h
00028 //  MS VC++    stdext      hash_map
00029 
00030 #define HAVE_GNU_EXT_HASH_MAP 1
00031 #define HAVE_STD_EXT_HASH_MAP 0
00032 #define HAVE_GLOBAL_HASH_MAP 0
00033 /* #undef HAVE_RW_STDEX_HASH_MAP_H */
00034 
00035 #if HAVE_GNU_EXT_HASH_MAP
00036 // This is for GCC-3.1+ which puts hash in ext/hash_map
00037 # include <ext/hash_map>
00038 # ifndef HASH_NAMESPACE
00039 #  define HASH_NAMESPACE __gnu_cxx
00040 # endif
00041 
00042 // GCC 3.0.x puts hash_map in <ext/hash_map> and in the std namespace.
00043 #elif HAVE_STD_EXT_HASH_MAP
00044 # include <ext/hash_map>
00045 # ifndef HASH_NAMESPACE
00046 #  define HASH_NAMESPACE std
00047 # endif
00048 
00049 // Older compilers such as GCC before version 3.0 do not keep
00050 // extensions in the `ext' directory, and ignore the `std' namespace.
00051 #elif HAVE_GLOBAL_HASH_MAP
00052 # include <hash_map>
00053 # ifndef HASH_NAMESPACE
00054 #  define HASH_NAMESPACE std
00055 # endif
00056 
00057 // HP aCC doesn't include an SGI-like hash_map. For this platform (or
00058 // any others using Rogue Wave Software's Tools.h++ library), we wrap
00059 // around them in std::
00060 #elif HAVE_RW_STDEX_HASH_MAP_H
00061 # include <rw/stdex/hashmap.h>
00062 # include <rw/stdex/hashmmap.h>
00063 # ifndef HASH_NAMESPACE
00064 #  define HASH_NAMESPACE std
00065 # endif
00066 
00067 // Support Microsoft VC++.
00068 #elif defined(_MSC_VER)
00069 # include <hash_map>
00070 # ifndef HASH_NAMESPACE
00071 #  define HASH_NAMESPACE stdext
00072    using std::_Distance;
00073 # endif
00074 
00075 // Give a warning if we couldn't find it, instead of (or in addition to)
00076 // randomly doing something dumb.
00077 #else
00078 # warning "Autoconfiguration failed to find the hash_map header file."
00079 #endif
00080 
00081 // we wrap Rogue Wave Tools.h++ rw_hashmap into something SGI-looking, here:
00082 #ifdef HAVE_RW_STDEX_HASH_MAP_H
00083 namespace HASH_NAMESPACE {
00084 
00085 template <class DataType> struct hash {
00086   unsigned int operator()(const unsigned int& x) const {
00087       return x;
00088   }
00089 };
00090 
00091 template <typename KeyType,
00092           typename ValueType,
00093           class _HashFcn = hash<KeyType>,
00094           class _EqualKey = equal_to<KeyType>,
00095           class _A = allocator <ValueType> >
00096 class hash_map : public rw_hashmap<KeyType, ValueType, class _HashFcn, 
00097                                    class _EqualKey, class _A> {
00098 };
00099 
00100 template <typename KeyType,
00101           typename ValueType,
00102           class _HashFcn = hash<KeyType>,
00103           class _EqualKey = equal_to<KeyType>,
00104           class _A = allocator <ValueType> >
00105 class hash_multimap : public rw_hashmultimap<KeyType, ValueType, class _HashFcn,
00106                                              class _EqualKey, class _A> {
00107 };
00108 
00109 } // end HASH_NAMESPACE;
00110 #endif
00111 
00112 // Include vector because ext/hash_map includes stl_vector.h and leaves
00113 // out specializations like stl_bvector.h, causing link conflicts.
00114 #include <vector>
00115 
00116 #ifdef _MSC_VER
00117 
00118 // GCC and VC++ have differing ways of implementing hash_maps.  As it's not
00119 // standardized, that's to be expected.  This adapter class allows VC++
00120 // hash_map to use GCC's hash classes.
00121 namespace stdext {
00122   template<class Key> struct hash;
00123   
00124   // Provide a hash function for unsigned ints...
00125   template<> struct hash<unsigned int> {
00126     inline size_t operator()(unsigned int Val) const {
00127       return Val;
00128     }
00129   };
00130 
00131   template<class Key> class hash_compare<Key, std::less<Key> > {
00132     std::less<Key> comp;
00133   public:
00134     enum { bucket_size = 4 };
00135     enum { min_buckets = 8 };
00136     hash_compare() {}
00137     hash_compare(std::less<Key> pred) : comp(pred) {}
00138     size_t operator()(const Key& key) const { return hash<Key>()(key); }
00139     bool operator()(const Key& k1, const Key& k2) const { return comp(k1, k2); }
00140   };
00141 }
00142 
00143 #endif
00144 
00145 using HASH_NAMESPACE::hash_map;
00146 using HASH_NAMESPACE::hash_multimap;
00147 using HASH_NAMESPACE::hash;
00148 
00149 #include "llvm/ADT/HashExtras.h"
00150 
00151 #endif // LLVM_ADT_HASH_MAP_H



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.