1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
|
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns:MSHelp="http://www.microsoft.com/MSHelp/" lang="en-us" xml:lang="en-us"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="DC.Type" content="reference">
<meta name="DC.Title" content="concurrent_unordered_map and concurrent_unordered_multimap Template Classes">
<meta name="DC.subject" content="concurrent_unordered_map, concurrent_unordered_multimap">
<meta name="keywords" content="concurrent_unordered_map, concurrent_unordered_multimap">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/construct_destroy_copy_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/size_and_capacity_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/container_iterators_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/modifiers_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/observers_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/lookup_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/parallel_iteration_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/bucket_interface_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/containers_overview/concurrent_unordered_map_cls/hash_policy_map_cls.htm">
<meta name="DC.Relation" scheme="URI" content="concurrent_hash_map_cls.htm">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="concurrent_unordered_map_cls">
<meta name="DC.Language" content="en-US">
<link rel="stylesheet" type="text/css" href="../../intel_css_styles.css">
<title>concurrent_unordered_map and concurrent_unordered_multimap Template Classes</title>
</head>
<body id="concurrent_unordered_map_cls">
<!-- ==============(Start:NavScript)================= -->
<script src="..\..\NavScript.js" language="JavaScript1.2" type="text/javascript"></script>
<script language="JavaScript1.2" type="text/javascript">WriteNavLink(2);</script>
<!-- ==============(End:NavScript)================= -->
<a name="concurrent_unordered_map_cls"><!-- --></a>
<h1 class="topictitle1"><samp class="codeph">concurrent_unordered_map</samp> and
<samp class="codeph">concurrent_unordered_multimap</samp> Template Classes</h1>
<div>
<div class="section"><h2 class="sectiontitle">Summary</h2>
<p>Template classes for associative containers that
supports concurrent insertion and traversal.
</p>
</div>
<div class="section"><h2 class="sectiontitle">Syntax</h2>
<pre>template <typename Key,
typename Element,
typename Hasher = tbb_hash<Key>,
typename Equality = std::equal_to<Key >,
typename Allocator = tbb::tbb_allocator<std::pair<const Key, Element > > >
class concurrent_unordered_map;</pre>
<pre>template <typename Key,
typename Element,
typename Hasher = tbb_hash<Key>,
typename Equality = std::equal_to<Key >,
typename Allocator = tbb::tbb_allocator<std::pair<const Key, Element > > >
class concurrent_unordered_multimap;</pre>
</div>
<div class="section"><h2 class="sectiontitle">Header</h2>
<pre>#include "tbb/concurrent_unordered_map.h"</pre>
</div>
<div class="section"><h2 class="sectiontitle">Description</h2>
<p><samp class="codeph">concurrent_unordered_map</samp> and
<samp class="codeph">concurrent_unordered_multimap</samp> support concurrent
insertion and traversal, but not concurrent erasure. The interfaces have no
visible locking. They may hold locks internally, but never while calling
user-defined code. They have semantics similar to the C++11
<samp class="codeph">std::unordered_map</samp> and
<samp class="codeph">std::unordered_multimap</samp> respectively, except as
follows:
</p>
<ul type="disc">
<li>
<p>Some methods requiring C++11 language features (such
as rvalue references and
<samp class="codeph">std::initializer_list</samp>) are omitted.
</p>
</li>
<li>
<p>The
<samp class="codeph">erase</samp> methods are prefixed with
<samp class="codeph">unsafe_</samp>, to indicate that they are not concurrency
safe.
</p>
</li>
<li>
<p>Bucket methods are prefixed with
<samp class="codeph">unsafe_</samp> as a reminder that they are not
concurrency safe with respect to insertion.
</p>
</li>
<li>
<p>The insert methods may create a temporary pair
that is destroyed if another thread inserts the same key concurrently.
</p>
</li>
<li>
<p>Like
<samp class="codeph">std::list</samp>, insertion of new items does
<em>not</em> invalidate any iterators, nor change the order of items
already in the map. Insertion and traversal may be concurrent.
</p>
</li>
<li>
<p>The iterator types
<samp class="codeph">iterator</samp> and
<samp class="codeph">const_iterator</samp> are of the forward iterator
category.
</p>
</li>
<li>
<p>Insertion does not invalidate or update the
iterators returned by
<samp class="codeph">equal_range</samp>, so insertion may cause non-equal
items to be inserted at the end of the range. However, the first iterator will
nonethless point to the equal item even after an insertion operation.
</p>
</li>
</ul>
<p>The following table lists the key differences between classes
<samp class="codeph">concurrent_unordered_map</samp> and
<samp class="codeph">concurrent_hash_map</samp> and
<samp class="codeph">concurrent_unordered_multimap</samp>.
</p>
<div class="tablenoborder"><table cellpadding="4" summary="" frame="border" border="1" cellspacing="0" rules="all"><thead align="left">
<tr>
<th class="cellrowborder" valign="top" width="37.453183520599254%" id="d41040e170">
<p>Class
</p>
</th>
<th class="cellrowborder" valign="top" width="62.546816479400746%" id="d41040e176">Key Difference
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="cellrowborder" valign="top" width="37.453183520599254%" headers="d41040e170 ">
<p><samp class="codeph">concurrent_hash_map</samp>
</p>
</td>
<td class="cellrowborder" valign="top" width="62.546816479400746%" headers="d41040e176 ">
<p>Permits concurrent erasure, and has built-in locking
</p>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="37.453183520599254%" headers="d41040e170 ">
<p><samp class="codeph">concurrent_unordered_map</samp>
</p>
</td>
<td class="cellrowborder" valign="top" width="62.546816479400746%" headers="d41040e176 ">
<ul type="disc">
<li>
<p>Permits concurrent traversal and insertion, no visible
locking, closely resembles the C++11 unordered_map.
</p>
</li>
<li>
<p> Has the
<samp class="codeph">[ ]</samp> and
<samp class="codeph">at</samp> accessors.
</p>
</li>
</ul>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="37.453183520599254%" headers="d41040e170 ">
<p><samp class="codeph">concurrent_unordered_multimap</samp>
</p>
</td>
<td class="cellrowborder" valign="top" width="62.546816479400746%" headers="d41040e176 ">
<ul type="disc">
<li>
<p> More than one
<samp class="codeph"><key,value></samp> pair with the same
<samp class="codeph">key</samp> value may be inserted in
<samp class="codeph">concurrent_unordered_multimap</samp>.
</p>
</li>
<li>
<p><samp class="codeph">find</samp> will return the
first
<samp class="codeph"><key,value></samp> pair with a matching
key at the point the search is made, though concurrent accesses to the
container may insert other pairs with the same key before the one returned.
</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
<div class="Note"><h3 class="NoteTipHead">
Caution</h3>
<p>As with any form of hash table, keys that are
equal must have the same hash code, and the ideal hash function distributes
keys uniformly across the hash code space.
</p>
</div>
</div>
<div class="section"><h2 class="sectiontitle">Members of both concurrent_unordered_map
and concurrent_unordered_multimap</h2>
<p>In the following synopsis, methods shown in
<samp class="codeph"><span style="color:blue"><strong>bold font</strong></span></samp>
may be concurrently invoked. For example, three different threads can
concurrently call methods
<samp class="codeph">insert</samp>,
<samp class="codeph">begin</samp>, and
<samp class="codeph">size</samp>. Their results might be non-deterministic. For
example, the result from size might correspond to before or after the
insertion.
</p>
<pre>
public:
<em>// types</em>
typedef Key key_type;
typedef std::pair<const Key, T> value_type;
typedef Element mapped_type;
typedef Hash hasher;
typedef Equality key_equal;
typedef Alloc allocator_type;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef <em>implementation-defined</em> size_type;
typedef <em>implementation-defined</em> difference_type;
typedef <em>implementation-defined</em> iterator;
typedef <em>implementation-defined</em> const_iterator;
typedef <em>implementation-defined</em> local_iterator;
typedef <em>implementation-defined</em> const_local_iterator;
allocator_type get_allocator() const;
<em>// size and capacity</em>
bool <span style="color:blue"><strong>empty()</strong></span> const; <em>// May take linear time!</em>
size_type <span style="color:blue"><strong>size()</strong></span> const; <em>// May take linear time!</em>
size_type max_size() const;
<em>// iterators</em>
iterator <span style="color:blue"><strong>begin()</strong></span>;
const_iterator <span style="color:blue"><strong>begin()</strong></span> const;
iterator <span style="color:blue"><strong>end()</strong></span>;
const_iterator <span style="color:blue"><strong>end()</strong></span> const;
const_iterator <span style="color:blue"><strong>cbegin()</strong></span> const;
const_iterator <span style="color:blue"><strong>cend()</strong></span> const;
<em>// modifiers</em>
std::pair<iterator, bool> <span style="color:blue"><strong>insert</strong></span>(const value_type& x);
iterator <span style="color:blue"><strong>insert</strong></span>(const_iterator hint, const value_type& x);
template<class InputIterator> void <span style="color:blue"><strong>insert</strong></span>(InputIterator first,
InputIterator last);
iterator unsafe_erase(const_iterator position);
size_type unsafe_erase(const key_type& k);
iterator unsafe_erase(const_iterator first, const_iterator last);
void clear();
<em>// observers</em>
hasher hash_function() const;
key_equal key_eq() const;
<em>// lookup</em>
iterator <span style="color:blue"><strong>find</strong></span>(const key_type& k);
const_iterator <span style="color:blue"><strong>find</strong></span>(const key_type& k) const;
size_type <span style="color:blue"><strong>count</strong></span>(const key_type& k) const;
std::pair<iterator, iterator> <span style="color:blue"><strong>equal_range</strong></span>(const key_type& k);
std::pair<const_iterator, const_iterator> <span style="color:blue"><strong>equal_range</strong></span>(const key_type& k) const;
<em>// parallel iteration</em>
typedef <em>implementation-defined</em> range_type;
typedef <em>implementation-defined</em> const_range_type;
range_type range();
const_range_type range() const;
<em>// bucket interface - for debugging</em>
size_type unsafe_bucket_count() const;
size_type unsafe_max_bucket_count() const;
size_type unsafe_bucket_size(size_type n);
size_type unsafe_bucket(const key_type& k) const;
local_iterator unsafe_begin(size_type n);
const_local_iterator unsafe_begin(size_type n) const;
local_iterator unsafe_end(size_type n);
const_local_iterator unsafe_end(size_type n) const;
const_local_iterator unsafe_cbegin(size_type n) const;
const_local_iterator unsafe_cend(size_type n) const;
<em>// hash policy</em>
float load_factor() const;
float max_load_factor() const;
void max_load_factor(float z);
void rehash(size_type n);
</pre>
</div>
<div class="section"><h2 class="sectiontitle">Members of concurrent_unordered_map</h2>
<p>In the following synopsis, methods in bold may be
concurrently invoked.
</p>
<pre>
public:
<em>// construct/destroy/copy</em>
explicit concurrent_unordered_map(size_type n = <em>implementation-defined</em>,
const Hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
template <typename InputIterator>
concurrent_unordered_map(
InputIterator first, InputIterator last,
size_type n = <em>implementation-defined</em>,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
concurrent_unordered_map(const concurrent_unordered_map&);
concurrent_unordered_map(const Alloc&);
concurrent_unordered_map(const concurrent_unordered_map&, const Alloc&);
<em>//C++11 specific</em>
concurrent_unordered_map(const std::initializer_list<value_type> &il,
size_type n = <em>implementation-defined</em>,
const Hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
~concurrent_unordered_map();
concurrent_unordered_map& operator=( const concurrent_unordered_map&);
<em>//C++11 specific</em>
concurrent_unordered_map& operator=( const std::initializer_list<value_type> &il);
void swap(concurrent_unordered_map&);
mapped_type& <span style="color:blue"><strong>operator[]</strong></span>(const key_type& k);
mapped_type& <span style="color:blue"><strong>at</strong></span>( const key_type& k );
const mapped_type& <span style="color:blue"><strong>at</strong></span>(const key_type& k) const;
</pre>
</div>
<div class="section"><h2 class="sectiontitle">Members of
concurrent_unordered_multimap</h2>
<pre>
public:
<em>// construct/destroy/copy</em>
explicit concurrent_unordered_multimap(size_type n = <em>implementation-defined</em>,
const Hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
template <typename InputIterator>
concurrent_unordered_multimap(
InputIterator first, InputIterator last,
size_type n = <em>implementation-defined</em>,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
concurrent_unordered_multimap(const concurrent_unordered_multimap&);
concurrent_unordered_multimap(const Alloc&);
concurrent_unordered_multimap(const concurrent_unordered_multimap&, const Alloc&);
<em>//C++11 specific</em>
concurrent_unordered_multimap(const std::initializer_list<value_type> &il,
size_type n = <em>implementation-defined</em>,
const Hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
~concurrent_unordered_multimap();
concurrent_unordered_multimap& operator=( const concurrent_unordered_multimap&);
<em>//C++11 specific</em>
concurrent_unordered_multimap& operator=( const std::initializer_list<value_type> &il);
void swap(concurrent_unordered_multimap&);
</pre>
</div>
</div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="../../reference/containers_overview.htm">Containers Overview</a></div>
</div>
<div class="See Also">
<ul class="ullinks">
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/construct_destroy_copy_map_cls.htm">Construct, Destroy, Copy</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/size_and_capacity_map_cls.htm">Size and capacity</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/container_iterators_map_cls.htm">Iterators</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/modifiers_map_cls.htm">Modifiers</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/observers_map_cls.htm">Observers</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/lookup_map_cls.htm">Lookup</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/parallel_iteration_map_cls.htm">Parallel Iteration</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/bucket_interface_map_cls.htm">Bucket Interface</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/containers_overview/concurrent_unordered_map_cls/hash_policy_map_cls.htm">Hash Policy</a><br>
</li>
</ul>
<h2>See Also</h2>
<div class="linklist">
<div><a href="concurrent_hash_map_cls.htm">concurrent_hash_map
</a></div></div>
</div>
</body>
</html>
|