HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ConcurrentHashMap.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ConcurrentHashMap.h (UT Library, C++)
7  *
8  * COMMENTS: Wrapper around Intel TBB's concurrent_hash_map container.
9  * Microsoft will probably have an implementation of this in their
10  * Concurrent Runtime Parallel Patterns Library (PPL) since they
11  * already have concurrent_vector and concurrent_queue.
12  *
13  */
14 
15 #ifndef __UT_CONCURRENTHASHMAP_H_INCLUDED__
16 #define __UT_CONCURRENTHASHMAP_H_INCLUDED__
17 
18 #include "UT_API.h"
19 #include <SYS/SYS_Types.h>
20 // IWYU pragma: begin_exports
21 #include <hboost/container_hash/hash.hpp>
22 #include <tbb/concurrent_hash_map.h>
23 // IWYU pragma: end_exports
24 #include <utility>
25 
26 namespace UT::detail
27 {
28 template <typename Key>
30 {
31 public:
32  std::size_t hash(const Key &a) const
33  {
34  return myHasher(a);
35  }
36  bool equal(const Key &a, const Key &b) const
37  {
38  return myEqual(a, b);
39  }
40 private:
41  hboost::hash<Key> myHasher;
42  std::equal_to<Key> myEqual;
43 };
44 }
45 
46 template
47 <
48  typename K,
49  typename T,
50  typename H = UT::detail::HashCompare<K>,
51  typename A = tbb::tbb_allocator<std::pair<const K, T>>
52 >
53 using UT_ConcurrentHashMap = tbb::concurrent_hash_map<K, T, H, A>;
54 
55 template<typename K, typename V, typename H, typename A>
56 int64
57 UTgetMemoryUsage(const UT_ConcurrentHashMap<K, V, H, A> &map, const bool inclusive)
58 {
59  int64 mem = 0;
60  if (inclusive)
61  mem += sizeof(map);
62 
63  // The size of the buckets (a mutex and a pointer to the first node)
64  mem += map.bucket_count()*(sizeof(intptr_t) + sizeof(void *));
65  // The size of the nodes (a mutex, a pointer to the next node,
66  // and an std::pair<K,V> forthe key and value)
67  mem += map.size()*(sizeof(intptr_t) + sizeof(void *) + sizeof(std::pair<K,V>));
68 
69  return mem;
70 }
71 
72 #endif // __UT_CONCURRENTHASHMAP_H_INCLUDED__
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
std::size_t hash(const Key &a) const
long long int64
Definition: SYS_Types.h:116
STATIC_INLINE uint64_t H(uint64_t x, uint64_t y, uint64_t mul, int r)
Definition: farmhash.h:762
tbb::concurrent_hash_map< K, T, H, A > UT_ConcurrentHashMap
int64 UTgetMemoryUsage(const UT_ConcurrentHashMap< K, V, H, A > &map, const bool inclusive)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
bool equal(const Key &a, const Key &b) const