mCRL2
Loading...
Searching...
No Matches
unordered_map.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote, Maurice Laveaux
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//
17
18#ifndef MCRL2_ATERMPP_STANDARD_CONTAINER_UNORDERED_MAP_H
19#define MCRL2_ATERMPP_STANDARD_CONTAINER_UNORDERED_MAP_H
20#pragma once
21
22#include <unordered_map>
25
27namespace atermpp
28{
29
31template < class Key,
32 class T,
33 class Hash = std::hash<detail::reference_aterm<Key> >,
34 class Pred = std::equal_to<detail::reference_aterm<Key> >,
35 class Alloc = std::allocator< std::pair<const detail::reference_aterm<Key>, detail::reference_aterm<T> > > >
36
37class unordered_map : public std::unordered_map< detail::reference_aterm<Key>, detail::reference_aterm<T>, Hash, Pred, Alloc >
38{
39protected:
40 typedef std::unordered_map< detail::reference_aterm<Key>, detail::reference_aterm<T>, Hash, Pred, Alloc > super;
41
43
44public:
45
47 typedef typename super::allocator_type allocator_type;
48 typedef typename super::value_type value_type;
49 typedef typename super::size_type size_type;
50 typedef typename super::node_type node_type;
51 typedef typename super::reference reference;
52 typedef typename super::iterator iterator;
53 typedef typename super::const_iterator const_iterator;
54 typedef typename super::insert_return_type insert_return_type;
55
58 : super(),
59 container_wrapper(*this)
60 {}
61
63 explicit unordered_map (const allocator_type& alloc)
64 : super::unordered_map(alloc),
65 container_wrapper(*this)
66 {}
67
70 : super::unordered_map(n, alloc),
71 container_wrapper(*this)
72 {}
73
75 : super::unordered_map(n, detail::reference_aterm(val), alloc),
76 container_wrapper(*this)
77 {}
78
80 template <class InputIterator>
81 unordered_map (InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
82 : super::unordered_map(first, last, alloc),
83 container_wrapper(*this)
84 {}
85
88 : super::unordered_map(x),
89 container_wrapper(*this)
90 {}
91
94 : super::unordered_map(x, alloc),
95 container_wrapper(*this)
96 {}
97
100 : super::unordered_map(std::move(x)),
101 container_wrapper(*this)
102 {}
103
104
107 : super::unordered_map(std::move(x), alloc),
108 container_wrapper(*this)
109 {}
110
112 unordered_map (std::initializer_list<value_type> il, const allocator_type& alloc = allocator_type())
113 : super::unordered_map(il, alloc),
114 container_wrapper(*this)
115 {}
116
118 unordered_map& operator=(const unordered_map& other)=default;
119
122
124 ~unordered_map()=default;
125
126 void clear() noexcept;
127
129 std::pair<iterator,bool> insert( const value_type& value );
130
131 template< class P >
132 std::pair<iterator,bool> insert( P&& value );
133
134 iterator insert( const_iterator hint, const value_type& value );
135
136 template< class P >
137 iterator insert( const_iterator hint, P&& value );
138
139 template< class InputIt >
140 void insert( InputIt first, InputIt last );
141
142 void insert( std::initializer_list<value_type> ilist );
143
145
147
148 template <class M>
149 std::pair<iterator, bool> insert_or_assign( const Key& k, M&& obj );
150
151 template <class M>
152 std::pair<iterator, bool> insert_or_assign( Key&& k, M&& obj );
153
154 template <class M>
155 iterator insert_or_assign( const_iterator hint, const Key& k, M&& obj );
156
157 template <class M>
158 iterator insert_or_assign( const_iterator hint, Key&& k, M&& obj );
159
160 template< class... Args >
161 std::pair<iterator,bool> emplace( Args&&... args );
162
163 template <class... Args>
164 iterator emplace_hint( const_iterator hint, Args&&... args );
165
166 template< class... Args >
167 std::pair<iterator, bool> try_emplace( const Key& k, Args&&... args );
168
169 template< class... Args >
170 std::pair<iterator, bool> try_emplace( Key&& k, Args&&... args );
171
172 template< class... Args >
173 iterator try_emplace( const_iterator hint, const Key& k, Args&&... args );
174
175 template< class... Args >
176 iterator try_emplace( const_iterator hint, Key&& k, Args&&... args );
177
178 iterator erase( iterator pos );
179
181
183
184 size_type erase( const Key& key );
185
186 void swap( unordered_map& other );
187
188 node_type extract( const_iterator position );
189
190 node_type extract( const Key& k );
191
192 template<class H2, class P2>
193 void merge( std::unordered_map<Key, T, H2, P2, allocator_type>& source );
194
195 template<class H2, class P2>
196 void merge( std::unordered_map<Key, T, H2, P2, allocator_type>&& source );
197
198 template<class H2, class P2>
199 void merge( std::unordered_multimap<Key, T, H2, P2, allocator_type>& source );
200
201 template<class H2, class P2>
202 void merge( std::unordered_multimap<Key, T, H2, P2, allocator_type>&& source );
203
204 std::size_t size() const
205 {
206 return super::size();
207 }
208
210 inline
211 iterator begin();
212
213 inline
214 iterator end();
215
217 const_iterator begin() const;
218 const_iterator end() const;
219
221 const_iterator cbegin() const;
222 const_iterator cend() const;
223
225 bool empty() const noexcept;
226
228 size_type max_size() const noexcept;
229};
230
231namespace utilities
232{
234template < class Key,
235 class T,
236 class Hash = std::hash<detail::reference_aterm<Key> >,
237 class Pred = std::equal_to<detail::reference_aterm<Key> >,
238 class Alloc = std::allocator< std::pair<const detail::reference_aterm<Key>, detail::reference_aterm<T> > >,
239 bool ThreadSafe = false >
240
241class unordered_map : public mcrl2::utilities::unordered_map< detail::reference_aterm<Key>,
242 detail::reference_aterm<T>, Hash, Pred, Alloc, ThreadSafe, false >
243{
244 protected:
246
248
249 public:
250
254 typedef typename super::size_type size_type;
255 typedef typename super::reference reference;
256 typedef typename super::iterator iterator;
258
261 : super(),
262 container_wrapper(*this)
263 {}
264
266 explicit unordered_map(const allocator_type& alloc)
267 : super::unordered_map(alloc),
268 container_wrapper(*this)
269 {}
270
273 : super::unordered_map(n, alloc),
274 container_wrapper(*this)
275 {}
276
278 : super::unordered_map(n, detail::reference_aterm(val), alloc),
279 container_wrapper(*this)
280 {}
281
283 template <class InputIterator>
284 unordered_map(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
285 : super::unordered_map(first, last, alloc),
286 container_wrapper(*this)
287 {}
288
291 : super::unordered_map(x),
292 container_wrapper(*this)
293 {}
294
297 : super::unordered_map(x, alloc),
298 container_wrapper(*this)
299 {}
300
303 : super::unordered_map(std::move(x)),
304 container_wrapper(*this)
305 {}
306
309 : super::unordered_map(std::move(x), alloc),
310 container_wrapper(*this)
311 {}
312
314 unordered_map(std::initializer_list<value_type> il, const allocator_type& alloc = allocator_type())
315 : super::unordered_map(il, alloc),
316 container_wrapper(*this)
317 {}
318
320 unordered_map& operator=(const unordered_map& other) = default;
321
324
326 ~unordered_map() = default;
327
328 void clear() noexcept;
329
332 template<typename ...Args>
333 iterator find(const Args&... args);
334
337 template<typename ...Args>
338 const_iterator find(const Args&... args) const;
339
340 std::pair<iterator, bool> insert(const value_type& value);
341
342 template< class P >
343 std::pair<iterator, bool> insert(P&& value);
344
346
347 template< class P >
348 iterator insert(const_iterator hint, P&& value);
349
350 template< class InputIt >
351 void insert(InputIt first, InputIt last);
352
353 void insert(std::initializer_list<value_type> ilist);
354
355 /*
356 insert_return_type insert(node_type&& nh);
357
358 iterator insert(const_iterator hint, node_type&& nh);
359 */
360
361 template <class M>
362 std::pair<iterator, bool> insert_or_assign(const Key& k, M&& obj);
363
364 template <class M>
365 std::pair<iterator, bool> insert_or_assign(Key&& k, M&& obj);
366
367 template <class M>
368 iterator insert_or_assign(const_iterator hint, const Key& k, M&& obj);
369
370 template <class M>
371 iterator insert_or_assign(const_iterator hint, Key&& k, M&& obj);
372
373 template< class... Args >
374 std::pair<iterator, bool> emplace(Args&&... args);
375
376 template <class... Args>
377 iterator emplace_hint(const_iterator hint, Args&&... args);
378
379 template< class... Args >
380 std::pair<iterator, bool> try_emplace(const Key& k, Args&&... args);
381
382 template< class... Args >
383 std::pair<iterator, bool> try_emplace(Key&& k, Args&&... args);
384
385 template< class... Args >
386 iterator try_emplace(const_iterator hint, const Key& k, Args&&... args);
387
388 template< class... Args >
389 iterator try_emplace(const_iterator hint, Key&& k, Args&&... args);
390
392
394
396
397 size_type erase(const Key& key);
398
399 void swap(unordered_map& other);
400
401 /*
402 node_type extract(const_iterator position);
403
404 node_type extract(const Key& k);
405
406 template<class H2, class P2>
407 void merge(std::unordered_map<Key, T, H2, P2, allocator_type>& source);
408
409 template<class H2, class P2>
410 void merge(std::unordered_map<Key, T, H2, P2, allocator_type>&& source);
411
412 template<class H2, class P2>
413 void merge(std::unordered_multimap<Key, T, H2, P2, allocator_type>& source);
414
415 template<class H2, class P2>
416 void merge(std::unordered_multimap<Key, T, H2, P2, allocator_type>&& source);
417 */
418
419 std::size_t size() const
420 {
421 return super::size();
422 }
423
425 iterator begin();
426 iterator end();
427
429 const_iterator begin() const;
430 const_iterator end() const;
431
433 const_iterator cbegin() const;
434 const_iterator cend() const;
435
437 bool empty() const noexcept;
438
440 size_type max_size() const noexcept;
441
442 protected:
443
445 void rehash(std::size_t /* new_size */);
446
447 void rehash_if_needed();
448};
449}
450
451} // namespace atermpp
452#endif // MCRL2_ATERMPP_STANDARD_CONTAINER_UNORDERED_MAP_H
453
454
Base class that should not be used.
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.
unordered_map(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
super::node_type node_type
unordered_map()
Default constructor.
iterator emplace_hint(const_iterator hint, Args &&... args)
unordered_map & operator=(unordered_map &&other)=default
Standard move assignment.
super::size_type size_type
unordered_map & operator=(const unordered_map &other)=default
Standard assignment.
~unordered_map()=default
Standard destructor.
unordered_map(unordered_map &&x, const allocator_type &alloc)
Constructor.
super::insert_return_type insert_return_type
unordered_map(const unordered_map &x, const allocator_type &alloc)
Constructor.
node_type extract(const_iterator position)
super::reference reference
std::unordered_map< detail::reference_aterm< Key >, detail::reference_aterm< T >, Hash, Pred, Alloc > super
unordered_map(InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type())
Constructor.
detail::generic_aterm_container< std::unordered_map< detail::reference_aterm< Key >, detail::reference_aterm< T >, Hash, Pred, Alloc > > container_wrapper
unordered_map(unordered_map &&x)
Constructor.
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)
unordered_map(std::initializer_list< value_type > il, const allocator_type &alloc=allocator_type())
Constructor. To be done later....
unordered_map(size_type n, const allocator_type &alloc=allocator_type())
Constructor.
std::pair< iterator, bool > insert_or_assign(const Key &k, M &&obj)
size_type max_size() const noexcept
unordered_map(const allocator_type &alloc)
Constructor.
super::allocator_type allocator_type
Standard typedefs.
std::size_t size() const
void swap(unordered_map &other)
unordered_map(const unordered_map &x)
Constructor.
super::const_iterator const_iterator
A unordered_map class in which aterms can be stored.
unordered_map(const allocator_type &alloc)
Constructor.
super::allocator_type allocator_type
Standard typedefs.
unordered_map(unordered_map &&x, const allocator_type &alloc)
Constructor.
unordered_map(const unordered_map &x)
Constructor.
unordered_map(unordered_map &&x)
Constructor.
unordered_map & operator=(const unordered_map &other)=default
Standard assignment.
unordered_map(size_type n, const allocator_type &alloc=allocator_type())
Constructor.
unordered_map(std::initializer_list< value_type > il, const allocator_type &alloc=allocator_type())
Constructor. To be done later....
~unordered_map()=default
Standard destructor.
unordered_map()
Default constructor.
mcrl2::utilities::unordered_map< detail::reference_aterm< Key >, detail::reference_aterm< T >, Hash, Pred, Alloc, ThreadSafe, false > super
unordered_map(const unordered_map &x, const allocator_type &alloc)
Constructor.
unordered_map(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
detail::generic_aterm_container< mcrl2::utilities::unordered_map< detail::reference_aterm< Key >, detail::reference_aterm< T >, Hash, Pred, Alloc, ThreadSafe, false > > container_wrapper
unordered_map(InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type())
Constructor.
unordered_map & operator=(unordered_map &&other)=default
Standard move assignment.
super::const_iterator const_iterator
A class for a map of keys to values in T based using the simple hash table set implementation.
typename Set::template unordered_set_iterator< bucket_type, false > iterator
typename std::allocator_traits< Allocator >::template rebind_alloc< value_type > allocator_type
typename Set::const_iterator const_iterator
std::pair< const Key, T > value_type
The main namespace for the aterm++ library.
Definition algorithm.h:21
STL namespace.