DDD 1.9.0.20250409152518
tbb_hash_map.hh
Go to the documentation of this file.
1#ifndef _CONCURRENT_HASH_MAP_HH_
2#define _CONCURRENT_HASH_MAP_HH_
3
4#ifdef REENTRANT
5
6#include <tbb/concurrent_hash_map.h>
7#include <tbb/mutex.h>
8
10
11template
12<
13 typename Key,
14 typename Data,
15 typename HashKey = d3::util::hash<Key>,
16 typename EqualKey = d3::util::equal<Key>
17>
18struct tbb_hash_map
19{
20 struct hash_compare
21 {
22 bool
23 equal( const Key& k1, const Key& k2)
24 {
25 return EqualKey()(k1,k2);
26 }
27
28 size_t
29 hash( const Key& k)
30 {
31 return HashKey()(k);
32 }
33
34 };
35
36 // Types
37 typedef tbb::mutex mutex;
38 typedef tbb::concurrent_hash_map<Key,Data,hash_compare> internal_hash_map;
39 typedef typename internal_hash_map::iterator iterator;
40 typedef typename internal_hash_map::const_iterator const_iterator;
41 typedef typename internal_hash_map::size_type size_type;
42 typedef typename internal_hash_map::accessor accessor;
43 typedef typename internal_hash_map::const_accessor const_accessor;
44
45 // Attributes
46 internal_hash_map map_;
47 mutex map_mutex_;
48
49 // Methods
50 tbb_hash_map()
51 :
52 map_(),
53 map_mutex_()
54 {
55 }
56
57 iterator
58 begin()
59 {
60 return map_.begin();
61 }
62
63 const_iterator
64 begin() const
65 {
66 return map_.begin();
67 }
68
69 iterator
70 end()
71 {
72 return map_.end();
73 }
74
75 const_iterator
76 end() const
77 {
78 return map_.end();
79 }
80
81 size_type
82 size() const
83 {
84 return map_.size();
85 }
86
87 bool
88 empty() const
89 {
90 return map_.empty();
91 }
92
93 void
94 clear()
95 {
96 // non reentrant method, need to lock the hash_map
97 mutex::scoped_lock lock(map_mutex_);
98 map_.clear();
99 }
100
101 bool
102 find( const_accessor& result, const Key& key) const
103 {
104 return map_.find(result,key);
105 }
106
107 bool
108 find( accessor& result, const Key& key)
109 {
110 return map_.find(result,key);
111 }
112
113 bool
114 insert( const_accessor& result, const Key& key)
115 {
116 return map_.insert(result,key);
117 }
118
119 bool
120 insert( accessor& result, const Key& key)
121 {
122 return map_.insert(result,key);
123 }
124
125 bool
126 erase( const Key& key)
127 {
128 return map_.erase(key);
129 }
130
131};
132
133#endif // REENTRANT
134
135#endif /* _CONCURRENT_HASH_MAP_HH_ */
Definition vector.hh:17

Please comment this page and report errors about it on the RefDocComments page.
Generated on Wed Apr 9 2025 15:27:42 for DDD by doxygen 1.9.8