hash.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef SPOT_MISC_HASH_HH
00025 # define SPOT_MISC_HASH_HH
00026
00027 # include <string>
00028 # include <functional>
00029 # include "hashfunc.hh"
00030
00031
00032 # ifdef __GNUC__
00033 # if __GNUC__ < 3
00034 # include <hash_map.h>
00035 # include <hash_set.h>
00036 namespace Sgi
00037 {
00038 using ::hash_map;
00039 using ::hash_multimap;
00040 using ::hash_set;
00041 using ::hash;
00042 }
00043 # else
00044 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
00045 # include <tr1/unordered_set>
00046 # include <tr1/unordered_map>
00047 namespace Sgi = std::tr1;
00048 # define hash_map unordered_map
00049 # define hash_multimap unordered_multimap
00050 # define hash_set unordered_set
00051 # else
00052 # include <ext/hash_map>
00053 # include <ext/hash_set>
00054 # if __GNUC__ == 3 && __GNUC_MINOR__ == 0
00055 namespace Sgi = std;
00056 # else
00057 namespace Sgi = ::__gnu_cxx;
00058 # endif
00059 # endif
00060 # endif
00061 # else // ... there are other compilers, right?
00062 # include <hash_map>
00063 # include <hash_set>
00064 namespace Sgi = std;
00065 # endif
00066
00067 namespace spot
00068 {
00069
00072 template <class T>
00073 struct ptr_hash :
00074 public std::unary_function<const T*, size_t>
00075 {
00076 size_t operator()(const T* p) const
00077 {
00078 return knuth32_hash(reinterpret_cast<const char*>(p)
00079 - static_cast<const char*>(0));
00080 }
00081 };
00082
00086 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
00087 typedef std::tr1::hash<std::string> string_hash;
00088 # else // GCC < 4.3
00089 struct string_hash :
00090 public Sgi::hash<const char*>,
00091 public std::unary_function<const std::string&, size_t>
00092 {
00093 size_t operator()(const std::string& s) const
00094 {
00095
00096
00097 return Sgi::hash<const char*>::operator()(s.c_str());
00098 }
00099 };
00101 # endif
00102 }
00103
00104 #endif // SPOT_MISC_HASH_HH