mCRL2
Loading...
Searching...
No Matches
unordered_map_implementation.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9//
13
14#ifndef MCRL2_ATERMPP_STANDARD_CONTAINER_DETAIL_UNORDERED_MAP_IMPLEMENTATION_H
15#define MCRL2_ATERMPP_STANDARD_CONTAINER_DETAIL_UNORDERED_MAP_IMPLEMENTATION_H
16
20
21namespace atermpp
22{
23
24 template< class Key, class T, class Hash, class Pred, class Alloc >
26 {
28 super::clear();
29 }
30
32 template< class Key, class T, class Hash, class Pred, class Alloc >
33 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc>::iterator,bool> unordered_map<Key,T,Hash,Pred,Alloc>::insert( const value_type& value )
34 {
36 return super::insert(value);
37 }
38
39 template< class Key, class T, class Hash, class Pred, class Alloc >
40 template< class P >
41 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc>::iterator,bool> unordered_map<Key,T,Hash,Pred,Alloc>::insert( P&& value )
42 {
44 return super::insert(value);
45 }
46
47 template< class Key, class T, class Hash, class Pred, class Alloc >
49 {
51 return super::insert(hint, value);
52 }
53
54 template< class Key, class T, class Hash, class Pred, class Alloc >
55 template< class P >
57 {
59 return super::insert(hint, value);
60 }
61
62 template< class Key, class T, class Hash, class Pred, class Alloc >
63 template< class InputIt >
64 void unordered_map<Key,T,Hash,Pred,Alloc>::insert( InputIt first, InputIt last )
65 {
67 super::insert(first, last);
68 }
69
70 template< class Key, class T, class Hash, class Pred, class Alloc >
71 void unordered_map<Key,T,Hash,Pred,Alloc>::insert( std::initializer_list<value_type> ilist )
72 {
74 super::insert(ilist);
75 }
76
77 template< class Key, class T, class Hash, class Pred, class Alloc >
79 {
81 return super::insert(nh);
82 }
83
84 template< class Key, class T, class Hash, class Pred, class Alloc >
86 {
88 return super::insert(hint, nh);
89 }
90
91 template< class Key, class T, class Hash, class Pred, class Alloc >
92 template <class M>
93 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc>::insert_or_assign( const Key& k, M&& obj )
94 {
96 return super::insert_or_assign(k, obj);
97 }
98
99 template< class Key, class T, class Hash, class Pred, class Alloc >
100 template <class M>
101 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc>::insert_or_assign( Key&& k, M&& obj )
102 {
104 return super::insert_or_assign(k, obj);
105 }
106
107 template< class Key, class T, class Hash, class Pred, class Alloc >
108 template <class M>
110 {
112 return super::insert_or_assign(hint, k, obj);
113 }
114
115 template< class Key, class T, class Hash, class Pred, class Alloc >
116 template <class M>
118 {
120 return super::insert_or_assign(hint, k, obj);
121 }
122
123 template< class Key, class T, class Hash, class Pred, class Alloc >
124 template< class... Args >
125 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc>::iterator,bool> unordered_map<Key,T,Hash,Pred,Alloc>::emplace( Args&&... args )
126 {
128 return super::emplace(args...);
129 }
130
131 template< class Key, class T, class Hash, class Pred, class Alloc >
132 template <class... Args>
134 {
136 return super::emplace_hint(hint, args...);
137 }
138
139 template< class Key, class T, class Hash, class Pred, class Alloc >
140 template< class... Args >
141 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc>::try_emplace( const Key& k, Args&&... args )
142 {
144 return super::try_emplace(k, args...);
145 }
146
147 template< class Key, class T, class Hash, class Pred, class Alloc >
148 template< class... Args >
149 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc>::try_emplace( Key&& k, Args&&... args )
150 {
152 return super::try_emplace(k, args...);
153 }
154
155 template< class Key, class T, class Hash, class Pred, class Alloc >
156 template< class... Args >
158 {
160 return super::try_emplace(hint, k, args...);
161 }
162
163 template< class Key, class T, class Hash, class Pred, class Alloc >
164 template< class... Args >
166 {
168 return super::try_emplace(hint, k, args...);
169 }
170
171 template< class Key, class T, class Hash, class Pred, class Alloc >
173 {
175 return super::erase(pos);
176 }
177
178 template< class Key, class T, class Hash, class Pred, class Alloc >
180 {
182 return super::erase(pos);
183 }
184
185 template< class Key, class T, class Hash, class Pred, class Alloc >
187 {
189 return super::erase(first, last);
190 }
191
192 template< class Key, class T, class Hash, class Pred, class Alloc >
194 {
196 return super::erase(key);
197 }
198
199 template< class Key, class T, class Hash, class Pred, class Alloc >
201 {
203 super::swap(other);
204 }
205
206 template< class Key, class T, class Hash, class Pred, class Alloc >
208 {
210 return extract(position);
211 }
212
213 template< class Key, class T, class Hash, class Pred, class Alloc >
215 {
217 return extract(k);
218 }
219
220 template< class Key, class T, class Hash, class Pred, class Alloc >
221 template<class H2, class P2>
222 void unordered_map<Key,T,Hash,Pred,Alloc>::merge( std::unordered_map<Key, T, H2, P2, allocator_type>& source )
223 {
225 return merge(source);
226 }
227
228 template< class Key, class T, class Hash, class Pred, class Alloc >
229 template<class H2, class P2>
230 void unordered_map<Key,T,Hash,Pred,Alloc>::merge( std::unordered_map<Key, T, H2, P2, allocator_type>&& source )
231 {
233 return merge(source);
234 }
235
236 template< class Key, class T, class Hash, class Pred, class Alloc >
237 template<class H2, class P2>
238 void unordered_map<Key,T,Hash,Pred,Alloc>::merge( std::unordered_multimap<Key, T, H2, P2, allocator_type>& source )
239 {
241 return merge(source);
242 }
243
244 template< class Key, class T, class Hash, class Pred, class Alloc >
245 template<class H2, class P2>
246 void unordered_map<Key,T,Hash,Pred,Alloc>::merge( std::unordered_multimap<Key, T, H2, P2, allocator_type>&& source )
247 {
249 return merge(source);
250 }
251
252 template< class Key, class T, class Hash, class Pred, class Alloc >
254 {
256 return super::begin();
257 }
258
259 template< class Key, class T, class Hash, class Pred, class Alloc >
261 {
263 return super::end();
264 }
265
266 template< class Key, class T, class Hash, class Pred, class Alloc >
268 {
270 return super::begin();
271 }
272
273 template< class Key, class T, class Hash, class Pred, class Alloc >
275 {
277 return super::end();
278 }
279
280 template< class Key, class T, class Hash, class Pred, class Alloc >
282 {
284 return super::cbegin();
285 }
286
287 template< class Key, class T, class Hash, class Pred, class Alloc >
289 {
291 return super::cend();
292 }
293
294 template< class Key, class T, class Hash, class Pred, class Alloc >
296 {
298 return super::empty();
299 }
300
301 template< class Key, class T, class Hash, class Pred, class Alloc >
303 {
305 return super::max_size();
306 }
307} // namespace atermpp
308
310
311 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
313 {
314 if constexpr (ThreadSafe)
315 {
317 super::rehash(new_size);
318 }
319 else
320 {
321 super::rehash(new_size);
322 }
323 }
324
325
326 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
329 // These functions are not thread safe.
331 std::size_t count = super::bucket_count();
332 if (super::load_factor() >= super::max_load_factor())
334 guard.unlock_shared();
335 rehash(count* 2);
336 }
337 }
339 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
341 {
343 super::clear();
344 }
346 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
347 template<typename ...Args>
349 {
350 if constexpr (ThreadSafe)
353 return super::find(args...);
354 }
355 return super::find(args...);
356 }
357
358 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
359 template<typename ...Args>
361 {
362 if (ThreadSafe)
363 {
365 return super::find(args...);
366 }
367 return super::find(args...);
369
370 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
371 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::insert(const value_type& value)
372 {
373 rehash_if_needed();
375 return super::insert(value);
376 }
378 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
379 template< class P >
380 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::insert(P&& value)
381 {
382 rehash_if_needed();
384 return super::insert(value);
385 }
387 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
390 rehash_if_needed();
392 return super::insert(hint, value);
394
395 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
396 template< class P >
398 {
399 rehash_if_needed();
401 return super::insert(hint, value);
402 }
403
404 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
405 template< class InputIt >
407 {
408 rehash_if_needed();
410 super::insert(first, last);
411 }
412
413 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
414 void unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::insert(std::initializer_list<value_type> ilist)
415 {
416 rehash_if_needed();
418 super::insert(ilist);
419 }
420
421 /*
422 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
423 insert_return_type insert(node_type&& nh)
424 {
425 mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
426 return super::insert(nh);
427 }
428
429 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
430 iterator insert(const_iterator hint, node_type&& nh)
431 {
432 mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
433 return super::insert(hint, nh);
435 */
436
437 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
438 template <class M>
439 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::insert_or_assign(const Key& k, M&& obj)
441 rehash_if_needed();
443 return super::insert_or_assign(k, obj);
444 }
446 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
447 template <class M>
448 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::insert_or_assign(Key&& k, M&& obj)
449 {
450 rehash_if_needed();
452 return super::insert_or_assign(k, obj);
453 }
454
455 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
456 template <class M>
458 {
459 rehash_if_needed();
461 return super::insert_or_assign(hint, k, obj);
462 }
463
464 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
465 template <class M>
467 {
468 rehash_if_needed();
470 return super::insert_or_assign(hint, k, obj);
471 }
472
473 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
474 template< class... Args >
475 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::emplace(Args&&... args)
476 {
477 rehash_if_needed();
479 return super::emplace(args...);
480 }
481
482 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
483 template <class... Args>
485 {
486 rehash_if_needed();
488 return super::emplace(hint, args...);
489 }
490
491 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
492 template< class... Args >
493 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::try_emplace(const Key& k, Args&&... args)
494 {
495 rehash_if_needed();
497 return super::try_emplace(k, args...);
498 }
499
500 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
501 template< class... Args >
502 std::pair<typename unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::iterator, bool> unordered_map<Key,T,Hash,Pred,Alloc,ThreadSafe>::try_emplace(Key&& k, Args&&... args)
503 {
504 rehash_if_needed();
506 return super::try_emplace(k, args...);
507 }
508
509 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
510 template< class... Args >
512 {
513 rehash_if_needed();
515 return super::try_emplace(hint, k, args...);
516 }
517
518 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
519 template< class... Args >
521 {
522 rehash_if_needed();
524 return super::try_emplace(hint, k, args...);
525 }
526
527 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
529 {
531 return super::erase(pos);
532 }
533
534 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
536 {
538 return super::erase(pos);
539 }
540
541 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
543 {
545 return super::erase(first, last);
546 }
547
548 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
550 {
552 return super::erase(key);
553 }
554
555 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
557 {
559 super::swap(other);
560 }
561
562 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
564 {
566 return super::begin();
567 }
568
569 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
571 {
573 return super::end();
574 }
575
576 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
578 {
580 return super::begin();
581 }
582
583 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
585 {
587 return super::end();
588 }
589
590 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
592 {
594 return super::cbegin();
595 }
596
597 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
599 {
601 return super::cend();
602 }
603
604 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
606 {
608 return super::empty();
609 }
610
611 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
613 {
615 return super::max_size();
616 }
617} // namespace atermpp::utilities
618
619#endif // MCRL2_ATERMPP_STANDARD_CONTAINER_DETAIL_UNORDERED_MAP_IMPLEMENTATION_H
mcrl2::utilities::lock_guard lock()
Acquire an exclusive lock.
mcrl2::utilities::shared_guard lock_shared()
Acquire a shared lock on this thread aterm pool.
A unordered_map class in which aterms can be stored.
std::pair< iterator, bool > try_emplace(const Key &k, Args &&... args)
std::pair< iterator, bool > insert(const value_type &value)
Inserts an element referring to a default value in the map.
super::node_type node_type
iterator emplace_hint(const_iterator hint, Args &&... args)
super::size_type size_type
super::insert_return_type insert_return_type
node_type extract(const_iterator position)
void merge(std::unordered_map< Key, T, H2, P2, allocator_type > &source)
super::iterator iterator
super::value_type value_type
std::pair< iterator, bool > emplace(Args &&... args)
std::pair< iterator, bool > insert_or_assign(const Key &k, M &&obj)
size_type max_size() const noexcept
void swap(unordered_map &other)
super::const_iterator const_iterator
A unordered_map class in which aterms can be stored.
std::pair< iterator, bool > try_emplace(const Key &k, Args &&... args)
iterator find(const Args &... args)
Standard find function in a map.
std::pair< iterator, bool > insert_or_assign(const Key &k, M &&obj)
iterator emplace_hint(const_iterator hint, Args &&... args)
std::pair< iterator, bool > insert(const value_type &value)
std::pair< iterator, bool > emplace(Args &&... args)
void rehash(std::size_t)
Function below is implemented in a .cpp file.
super::const_iterator const_iterator
An exclusive lock guard for the shared_mutex.
A shared lock guard for the shared_mutex.
void unlock_shared()
Unlocks the acquired shared guard explicitly. Otherwise, performed in destructor.
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
The main namespace for the aterm++ library.
Definition algorithm.h:21