00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SPOT_MISC_HASH_HH
00023 # define SPOT_MISC_HASH_HH
00024
00025 # include <string>
00026 # include <functional>
00027
00028
00029 # ifdef __GNUC__
00030 # if __GNUC__ < 3
00031 # include <hash_map.h>
00032 # include <hash_set.h>
00033 namespace Sgi
00034 {
00035 using ::hash_map;
00036 using ::hash_set;
00037 using ::hash;
00038 };
00039 # else
00040 # include <ext/hash_map>
00041 # include <ext/hash_set>
00042 # if __GNUC_MINOR__ == 0
00043 namespace Sgi = std;
00044 # else
00045 namespace Sgi = ::__gnu_cxx;
00046 # endif
00047 # endif
00048 # else // ... there are other compilers, right?
00049 # include <hash_map>
00050 # include <hash_set>
00051 namespace Sgi = std;
00052 # endif
00053
00054 namespace spot
00055 {
00056
00058 template <class T>
00059 struct ptr_hash :
00060 public std::unary_function<const T*, size_t>
00061 {
00062 size_t operator()(const T* p) const
00063 {
00064 return reinterpret_cast<const char*>(p) - static_cast<const char*>(0);
00065 }
00066 };
00067
00069 struct string_hash :
00070 public Sgi::hash<const char*>,
00071 public std::unary_function<const std::string&, size_t>
00072 {
00073 size_t operator()(const std::string& s) const
00074 {
00075
00076
00077 return Sgi::hash<const char*>::operator()(s.c_str());
00078 }
00079 };
00080 }
00081
00082 #endif // SPOT_MISC_HASH_HH