|
Sierra Toolkit
Version of the Day
|
00001 #ifndef RDESTL_HASH_H 00002 #define RDESTL_HASH_H 00003 00004 namespace rde 00005 { 00006 00007 typedef unsigned long hash_value_t; 00008 00009 // Default implementations, just casts to hash_value. 00010 template<typename T> 00011 hash_value_t extract_int_key_value(const T& t) 00012 { 00013 return (hash_value_t)t; 00014 } 00015 00016 // Default implementation of hasher. 00017 // Works for keys that can be converted to 32-bit integer 00018 // with extract_int_key_value. 00019 // Algorithm by Robert Jenkins. 00020 // (see http://www.cris.com/~Ttwang/tech/inthash.htm for example). 00021 template<typename T> 00022 struct hash 00023 { 00024 hash_value_t operator()(const T& t) const 00025 { 00026 hash_value_t a = extract_int_key_value(t); 00027 a = (a+0x7ed55d16) + (a<<12); 00028 a = (a^0xc761c23c) ^ (a>>19); 00029 a = (a+0x165667b1) + (a<<5); 00030 a = (a+0xd3a2646c) ^ (a<<9); 00031 a = (a+0xfd7046c5) + (a<<3); 00032 a = (a^0xb55a4f09) ^ (a>>16); 00033 return a; 00034 } 00035 }; 00036 00037 } 00038 00039 #endif