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 # include "hashfunc.hh"
00028
00029
00030 # ifdef __GNUC__
00031 # if __GNUC__ < 3
00032 # include <hash_map.h>
00033 # include <hash_set.h>
00034 namespace Sgi
00035 {
00036 using ::hash_map;
00037 using ::hash_set;
00038 using ::hash;
00039 };
00040 # else
00041 # include <ext/hash_map>
00042 # include <ext/hash_set>
00043 # if __GNUC__ == 3 && __GNUC_MINOR__ == 0
00044 namespace Sgi = std;
00045 # else
00046 namespace Sgi = ::__gnu_cxx;
00047 # endif
00048 # endif
00049 # else // ... there are other compilers, right?
00050 # include <hash_map>
00051 # include <hash_set>
00052 namespace Sgi = std;
00053 # endif
00054
00055 namespace spot
00056 {
00057
00060 template <class T>
00061 struct ptr_hash :
00062 public std::unary_function<const T*, size_t>
00063 {
00064 size_t operator()(const T* p) const
00065 {
00066 return knuth32_hash(reinterpret_cast<const char*>(p)
00067 - static_cast<const char*>(0));
00068 }
00069 };
00070
00073 struct string_hash :
00074 public Sgi::hash<const char*>,
00075 public std::unary_function<const std::string&, size_t>
00076 {
00077 size_t operator()(const std::string& s) const
00078 {
00079
00080
00081 return Sgi::hash<const char*>::operator()(s.c_str());
00082 }
00083 };
00084 }
00085
00086 #endif // SPOT_MISC_HASH_HH