Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:50

0001 /*
0002     Copyright (c) 2005-2020 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 // must be included outside namespaces.
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 // Template class for hash compare
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         // TODO: get rid of the result invertion
0047         return (!my_key_compare_object(key1, key2));
0048     }
0049 
0050     Hasher       my_hash_object;        // The hash object
0051     Key_equality my_key_compare_object; // The equality comparator object
0052 };
0053 
0054 //! Hash multiplier
0055 static const size_t hash_multiplier = tbb::internal::select_size_t_constant<2654435769U, 11400714819323198485ULL>::value;
0056 
0057 } // namespace internal
0058 
0059 //! Hasher functions
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 } // namespace interface5
0082 using interface5::tbb_hasher;
0083 
0084 // Template class for hash compare
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 //! hash_compare that is default argument for concurrent_hash_map
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 }  // namespace tbb
0105 #endif  /*  __TBB_tbb_hash_compare_impl_H */