ms_hash_wrapper.h
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
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef ms_hash_wrapper_H
00041 #define ms_hash_wrapper_H
00042
00043 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) // Look below after the macros for the end of this
00044
00045 #if __GNUC__ < 3
00046 #error GNUC < 3 is not supported!!
00047 #endif
00048
00049 # include <ext/hash_set>
00050 # include <ext/hash_map>
00051
00052 # if __GNUC__ == 3 && __GNUC_MINOR__ == 0 // GCC 3.0
00053 # define __NMSPACE__ std
00054 # else // GCC 3.1 or later
00055 using namespace __gnu_cxx;
00056 # define __NMSPACE__ __gnu_cxx
00057 # endif
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #define SET_HASH_WITH_FUNCTION(type, paramName, hashFunc) \
00108 namespace __NMSPACE__ { \
00109 template<> \
00110 struct hash< type > \
00111 { \
00112 size_t operator()(type paramName) const \
00113 { \
00114 return (size_t)(hashFunc); \
00115 } \
00116 }; \
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126 #define SET_HASH_WITH_INHERITANCE(type, originalType, paramName, hashFunc) \
00127 namespace __NMSPACE__ { \
00128 template<> \
00129 struct hash< type > \
00130 { \
00131 size_t operator()(type paramName) const \
00132 { \
00133 return hash< originalType >()(hashFunc); \
00134 } \
00135 }; \
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 #define SET_HASH_FUNCTION(type, templateClass, paramName, hashFunc) \
00153 namespace __NMSPACE__ { \
00154 template<class templateClass > \
00155 struct hash< type > \
00156 { \
00157 size_t operator()(type paramName) const \
00158 { \
00159 return hash< templateClass >()(hashFunc); \
00160 } \
00161 }; \
00162 }
00163 #endif // __GNUC__
00164
00168
00169 #if (defined(WIN32) || defined(__INTEL_COMPILER)) && !defined(_MINGW_) && !defined(__GNUC__) // MinGW runs under gcc...
00170
00171 #include <hash_set>
00172 #include <hash_map>
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 #define SET_HASH_WITH_FUNCTION(type, paramName, hashFunc) \
00184 namespace stdext { \
00185 template<class _Kty> \
00186 class hash_compare<type, std::less<_Kty> > \
00187 { \
00188 public: \
00189 enum \
00190 { \
00191 bucket_size = 4, \
00192 min_buckets = 8}; \
00193 \
00194 hash_compare() \
00195 : comp() \
00196 { \
00197 } \
00198 \
00199 hash_compare(std::less<_Kty> _Pred) \
00200 : comp(_Pred) \
00201 { \
00202 } \
00203 \
00204 size_t operator()(const type& paramName) const \
00205 { \
00206 return (size_t)(hashFunc); \
00207 } \
00208 \
00209 bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const\
00210 { \
00211 return (comp(_Keyval1, _Keyval2)); \
00212 } \
00213 \
00214 protected: \
00215 std::less<_Kty> comp; \
00216 \
00217 }; \
00218 } // end of namespace stdext
00219
00220
00221
00222
00223
00224
00225
00226
00227 #define SET_HASH_WITH_INHERITANCE(type, originalType, paramName, hashFunc)\
00228 namespace stdext { \
00229 template<class _Kty> \
00230 class hash_compare<type, std::less<_Kty> > \
00231 { \
00232 public: \
00233 enum \
00234 { \
00235 bucket_size = 4, \
00236 min_buckets = 8}; \
00237 \
00238 hash_compare() \
00239 : comp() \
00240 { } \
00241 \
00242 hash_compare(std::less<_Kty> _Pred) \
00243 : comp(_Pred) \
00244 { } \
00245 \
00246 size_t operator()(const type& paramName) const \
00247 { \
00248 return hash_compare< originalType >()(hashFunc); \
00249 } \
00250 \
00251 bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const \
00252 { \
00253 return (comp(_Keyval1, _Keyval2)); \
00254 } \
00255 \
00256 protected: \
00257 std::less<_Kty> comp; \
00258 \
00259 }; }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 #define SET_HASH_FUNCTION(type, templateClass, paramName, hashFunc) \
00277 namespace stdext { \
00278 template<class templateClass > \
00279 class hash_compare<type, std::less< templateClass > > \
00280 { \
00281 public: \
00282 enum \
00283 { \
00284 bucket_size = 4, \
00285 min_buckets = 8}; \
00286 \
00287 hash_compare() \
00288 : comp() \
00289 { \
00290 } \
00291 \
00292 hash_compare(std::less< templateClass > _Pred) \
00293 : comp(_Pred) \
00294 { \
00295 } \
00296 \
00297 size_t operator()(const type& paramName) const \
00298 { \
00299 return hash_compare< templateClass >()(hashFunc); \
00300 } \
00301 \
00302 bool operator()(const templateClass& _Keyval1, const templateClass& _Keyval2) const \
00303 { \
00304 return (comp(_Keyval1, _Keyval2)); \
00305 } \
00306 \
00307 protected: \
00308 std::less< templateClass > comp; \
00309 \
00310 }; }
00311
00312 #endif // WIN32
00313
00314
00318
00319 #if defined(__GNUC__) && defined(__INTEL_COMPILER)
00320
00321 #include <hash_set>
00322 #include <hash_map>
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 #define SET_HASH_WITH_FUNCTION(type, paramName, hashFunc) \
00334 namespace std { \
00335 template<class _Kty> \
00336 class hash_compare<type, std::less<_Kty> > \
00337 { \
00338 public: \
00339 enum \
00340 { \
00341 bucket_size = 4, \
00342 min_buckets = 8}; \
00343 \
00344 hash_compare() \
00345 : comp() \
00346 { \
00347 } \
00348 \
00349 hash_compare(std::less<_Kty> _Pred) \
00350 : comp(_Pred) \
00351 { \
00352 } \
00353 \
00354 size_t operator()(const type& paramName) const \
00355 { \
00356 return (size_t)(hashFunc); \
00357 } \
00358 \
00359 bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const\
00360 { \
00361 return (comp(_Keyval1, _Keyval2)); \
00362 } \
00363 \
00364 protected: \
00365 std::less<_Kty> comp; \
00366 \
00367 }; \
00368 } // end of namespace std
00369
00370
00371
00372
00373
00374
00375
00376
00377 #define SET_HASH_WITH_INHERITANCE(type, originalType, paramName, hashFunc)\
00378 namespace std { \
00379 template<class _Kty> \
00380 class hash_compare<type, std::less<_Kty> > \
00381 { \
00382 public: \
00383 enum \
00384 { \
00385 bucket_size = 4, \
00386 min_buckets = 8}; \
00387 \
00388 hash_compare() \
00389 : comp() \
00390 { } \
00391 \
00392 hash_compare(std::less<_Kty> _Pred) \
00393 : comp(_Pred) \
00394 { } \
00395 \
00396 size_t operator()(const type& paramName) const \
00397 { \
00398 return hash_compare< originalType >()(hashFunc); \
00399 } \
00400 \
00401 bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const \
00402 { \
00403 return (comp(_Keyval1, _Keyval2)); \
00404 } \
00405 \
00406 protected: \
00407 std::less<_Kty> comp; \
00408 \
00409 }; }
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 #define SET_HASH_FUNCTION(type, templateClass, paramName, hashFunc) \
00427 namespace std { \
00428 template<class templateClass > \
00429 class hash_compare<type, std::less< templateClass > > \
00430 { \
00431 public: \
00432 enum \
00433 { \
00434 bucket_size = 4, \
00435 min_buckets = 8}; \
00436 \
00437 hash_compare() \
00438 : comp() \
00439 { \
00440 } \
00441 \
00442 hash_compare(std::less< templateClass > _Pred) \
00443 : comp(_Pred) \
00444 { \
00445 } \
00446 \
00447 size_t operator()(const type& paramName) const \
00448 { \
00449 return hash_compare< templateClass >()(hashFunc); \
00450 } \
00451 \
00452 bool operator()(const templateClass& _Keyval1, const templateClass& _Keyval2) const \
00453 { \
00454 return (comp(_Keyval1, _Keyval2)); \
00455 } \
00456 \
00457 protected: \
00458 std::less< templateClass > comp; \
00459 \
00460 }; }
00461
00462 #endif // WIN32
00463
00464 #endif // ms_hash_wrapper_H
Generated on Tue Aug 17 15:59:04 2004 for PLearn by
1.3.7