Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
_tbb_hash_compare_impl.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2019 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 // must be included outside namespaces.
22 #ifndef __TBB_tbb_hash_compare_impl_H
23 #define __TBB_tbb_hash_compare_impl_H
24 
25 #include <string>
26 
27 namespace tbb {
28 namespace interface5 {
29 namespace internal {
30 
31 // Template class for hash compare
32 template<typename Key, typename Hasher, typename Key_equality>
34 {
35 public:
36  typedef Hasher hasher;
37  typedef Key_equality key_equal;
38 
40 
41  hash_compare(Hasher a_hasher) : my_hash_object(a_hasher) {}
42 
43  hash_compare(Hasher a_hasher, Key_equality a_keyeq) : my_hash_object(a_hasher), my_key_compare_object(a_keyeq) {}
44 
45  size_t operator()(const Key& key) const {
46  return ((size_t)my_hash_object(key));
47  }
48 
49  bool operator()(const Key& key1, const Key& key2) const {
50  // TODO: get rid of the result invertion
51  return (!my_key_compare_object(key1, key2));
52  }
53 
54  Hasher my_hash_object; // The hash object
55  Key_equality my_key_compare_object; // The equality comparator object
56 };
57 
60 
61 } // namespace internal
62 
64 template<typename T>
65 inline size_t tbb_hasher( const T& t ) {
66  return static_cast<size_t>( t ) * internal::hash_multiplier;
67 }
68 template<typename P>
69 inline size_t tbb_hasher( P* ptr ) {
70  size_t const h = reinterpret_cast<size_t>( ptr );
71  return (h >> 3) ^ h;
72 }
73 template<typename E, typename S, typename A>
74 inline size_t tbb_hasher( const std::basic_string<E,S,A>& s ) {
75  size_t h = 0;
76  for( const E* c = s.c_str(); *c; ++c )
77  h = static_cast<size_t>(*c) ^ (h * internal::hash_multiplier);
78  return h;
79 }
80 template<typename F, typename S>
81 inline size_t tbb_hasher( const std::pair<F,S>& p ) {
82  return tbb_hasher(p.first) ^ tbb_hasher(p.second);
83 }
84 
85 } // namespace interface5
87 
88 // Template class for hash compare
89 template<typename Key>
90 class tbb_hash
91 {
92 public:
93  tbb_hash() {}
94 
95  size_t operator()(const Key& key) const
96  {
97  return tbb_hasher(key);
98  }
99 };
100 
102 template<typename Key>
104  static size_t hash( const Key& a ) { return tbb_hasher(a); }
105  static bool equal( const Key& a, const Key& b ) { return a == b; }
106 };
107 
108 } // namespace tbb
109 #endif /* __TBB_tbb_hash_compare_impl_H */
A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size...
Definition: tbb_stddef.h:477
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function h
size_t tbb_hasher(const T &t)
Hasher functions.
static const size_t hash_multiplier
Hash multiplier.
size_t tbb_hasher(const std::pair< F, S > &p)
hash_compare(Hasher a_hasher, Key_equality a_keyeq)
static bool equal(const Key &a, const Key &b)
hash_compare that is default argument for concurrent_hash_map
void const char const char int ITT_FORMAT __itt_group_sync p
The graph class.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle * key
void const char const char int ITT_FORMAT __itt_group_sync s
size_t operator()(const Key &key) const
static size_t hash(const Key &a)
bool operator()(const Key &key1, const Key &key2) const

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.