File indexing completed on 2025-01-18 10:12:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef __TBB_tbb_hash_compare_impl_H
0019 #define __TBB_tbb_hash_compare_impl_H
0020
0021 #include <string>
0022
0023 namespace tbb {
0024 namespace interface5 {
0025 namespace internal {
0026
0027
0028 template<typename Key, typename Hasher, typename Key_equality>
0029 class hash_compare
0030 {
0031 public:
0032 typedef Hasher hasher;
0033 typedef Key_equality key_equal;
0034
0035 hash_compare() {}
0036
0037 hash_compare(Hasher a_hasher) : my_hash_object(a_hasher) {}
0038
0039 hash_compare(Hasher a_hasher, Key_equality a_keyeq) : my_hash_object(a_hasher), my_key_compare_object(a_keyeq) {}
0040
0041 size_t operator()(const Key& key) const {
0042 return ((size_t)my_hash_object(key));
0043 }
0044
0045 bool operator()(const Key& key1, const Key& key2) const {
0046
0047 return (!my_key_compare_object(key1, key2));
0048 }
0049
0050 Hasher my_hash_object;
0051 Key_equality my_key_compare_object;
0052 };
0053
0054
0055 static const size_t hash_multiplier = tbb::internal::select_size_t_constant<2654435769U, 11400714819323198485ULL>::value;
0056
0057 }
0058
0059
0060 template<typename T>
0061 __TBB_DEPRECATED_MSG("tbb::tbb_hasher is deprecated, use std::hash") inline size_t tbb_hasher( const T& t ) {
0062 return static_cast<size_t>( t ) * internal::hash_multiplier;
0063 }
0064 template<typename P>
0065 __TBB_DEPRECATED_MSG("tbb::tbb_hasher is deprecated, use std::hash") inline size_t tbb_hasher( P* ptr ) {
0066 size_t const h = reinterpret_cast<size_t>( ptr );
0067 return (h >> 3) ^ h;
0068 }
0069 template<typename E, typename S, typename A>
0070 __TBB_DEPRECATED_MSG("tbb::tbb_hasher is deprecated, use std::hash") inline size_t tbb_hasher( const std::basic_string<E,S,A>& s ) {
0071 size_t h = 0;
0072 for( const E* c = s.c_str(); *c; ++c )
0073 h = static_cast<size_t>(*c) ^ (h * internal::hash_multiplier);
0074 return h;
0075 }
0076 template<typename F, typename S>
0077 __TBB_DEPRECATED_MSG("tbb::tbb_hasher is deprecated, use std::hash") inline size_t tbb_hasher( const std::pair<F,S>& p ) {
0078 return tbb_hasher(p.first) ^ tbb_hasher(p.second);
0079 }
0080
0081 }
0082 using interface5::tbb_hasher;
0083
0084
0085 template<typename Key>
0086 class __TBB_DEPRECATED_MSG("tbb::tbb_hash is deprecated, use std::hash") tbb_hash
0087 {
0088 public:
0089 tbb_hash() {}
0090
0091 size_t operator()(const Key& key) const
0092 {
0093 return tbb_hasher(key);
0094 }
0095 };
0096
0097
0098 template<typename Key>
0099 struct tbb_hash_compare {
0100 static size_t hash( const Key& a ) { return tbb_hasher(a); }
0101 static bool equal( const Key& a, const Key& b ) { return a == b; }
0102 };
0103
0104 }
0105 #endif