00001
00002 #ifndef __UPF_HASHES_H__
00003 #define __UPF_HASHES_H__
00004
00005 #ifdef HAVE_CONFIG_H
00006 #include "config.h"
00007 #endif
00008
00009 #if defined(HAVE_EXT_HASH_MAP)
00010 #include <ext/hash_map>
00011 #ifdef __GNUC__
00012 using namespace __gnu_cxx;
00013 #endif
00014 #define USE_HASH
00015 #elif defined(HAVE_HASH_MAP)
00016 #include <hash_map>
00017 #define USE_HASH
00018 #else
00019 #include <map>
00020 #endif
00021
00022
00023 #ifdef USE_HASH
00024 #define best_map_type hash_map
00025 #else
00026 #define best_map_type map
00027 #endif
00028
00029
00030 namespace upf { namespace impl {
00031
00032 using namespace std;
00033
00034
00035
00036
00037
00038 #ifdef USE_HASH
00039 struct eqstr
00040 {
00041 bool operator()(const string& s1, const string& s2) const
00042 {
00043 return s1 == s2;
00044 }
00045 };
00046
00047 struct stringhash
00048 {
00049 hash<const char*> impl;
00050 size_t operator()(const string& s) const { return impl(s.c_str()); }
00051 };
00052
00053 template<class T> class StringHash : public hash_map<string, T, stringhash, eqstr> {};
00054
00055 #else
00056 struct ltstr
00057 {
00058 bool operator()(const string& s1, const string& s2) const
00059 {
00060 return s1.compare(s2) < 0;
00061 }
00062 };
00063
00064 template<class T> class StringHash : public std::map<std::string, T, ltstr> {};
00065 #endif
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #ifdef USE_HASH
00077
00078 struct IID_hash
00079 {
00080 size_t operator()(const upf::IID& x) const
00081 {
00082 return x.data1+x.data2+x.data3+x.data4+x.version_major+x.version_minor;
00083 }
00084 };
00085
00086 template<class T> class IIDHash : public hash_map< ::upf::IID, T, IID_hash> {};
00087
00088 #else
00089
00090 struct IID_lt
00091 {
00092 bool operator()(const upf::IID& i1, const upf::IID& i2) const
00093 {
00094 #define __UPF_CMP(field) \
00095 if (i1.field != i2.field) return i1.field < i2.field
00096 __UPF_CMP(data1);
00097 __UPF_CMP(data2);
00098 __UPF_CMP(data3);
00099 __UPF_CMP(data4);
00100 __UPF_CMP(version_major);
00101 __UPF_CMP(version_minor);
00102 #undef __UPF_CMP
00103 return false;
00104 }
00105 };
00106
00107 template<class T> class IIDHash : public map< ::upf::IID, T, IID_lt> {};
00108
00109 #endif
00110
00111
00112
00113 } }
00114
00115 #endif