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//
10/// \file mcrl2/atermpp/standard_containers/detail/unordered_map_implementation.h
11/// \brief This file contains an implementation of the hash function
12/// to break circular header dependencies.
13
14#ifndef MCRL2_ATERMPP_STANDARD_CONTAINER_DETAIL_UNORDERED_MAP_IMPLEMENTATION_H
15#define MCRL2_ATERMPP_STANDARD_CONTAINER_DETAIL_UNORDERED_MAP_IMPLEMENTATION_H
16
17#include "mcrl2/atermpp/standard_containers/unordered_map.h"
18#include "mcrl2/atermpp/detail/thread_aterm_pool.h"
19#include "mcrl2/utilities/shared_mutex.h"
20
21namespace atermpp
22{
23
24 template< class Key, class T, class Hash, class Pred, class Alloc >
26 {
27 if (this != &other)
28 {
29 mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
31 }
32 return *this;
33 }
34
35 template< class Key, class T, class Hash, class Pred, class Alloc >
37 {
38 if (this != &other)
39 {
40 mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
42 }
43 return *this;
44 }
45
46 template< class Key, class T, class Hash, class Pred, class Alloc >
47 void unordered_map<Key,T,Hash,Pred,Alloc>::clear() noexcept
48 {
49 mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
51 }
52
53 /// \brief Inserts an element referring to a default value in the map.
54 template< class Key, class T, class Hash, class Pred, class Alloc >
56 {
57 mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
58 return m_container.insert(value);
59 }
60
61 template< class Key, class T, class Hash, class Pred, class Alloc >
62 template< class P >
65 {
68 }
69
70 template< class Key, class T, class Hash, class Pred, class Alloc >
72 {
75 }
76
77 template< class Key, class T, class Hash, class Pred, class Alloc >
78 template< class P >
81 {
84 }
85
86 template< class Key, class T, class Hash, class Pred, class Alloc >
87 template< class InputIt >
89 {
92 }
93
94 template< class Key, class T, class Hash, class Pred, class Alloc >
96 {
99 }
100
101 template< class Key, class T, class Hash, class Pred, class Alloc >
103 {
105 return m_container.insert(std::move(nh));
106 }
107
108 template< class Key, class T, class Hash, class Pred, class Alloc >
110 {
112 return m_container.insert(hint, std::move(nh));
113 }
114
115 template< class Key, class T, class Hash, class Pred, class Alloc >
116 template <class M>
118 {
121 }
122
123 template< class Key, class T, class Hash, class Pred, class Alloc >
124 template <class M>
126 {
129 }
130
131 template< class Key, class T, class Hash, class Pred, class Alloc >
132 template <class M>
134 {
137 }
138
139 template< class Key, class T, class Hash, class Pred, class Alloc >
140 template <class M>
142 {
145 }
146
147 template< class Key, class T, class Hash, class Pred, class Alloc >
148 template< class... Args >
150 {
152 return m_container.emplace(std::forward<Args>(args)...);
153 }
154
155 template< class Key, class T, class Hash, class Pred, class Alloc >
156 template <class... Args>
158 {
161 }
162
163 template< class Key, class T, class Hash, class Pred, class Alloc >
164 template< class... Args >
166 {
169 }
170
171 template< class Key, class T, class Hash, class Pred, class Alloc >
172 template< class... Args >
174 {
177 }
178
179 template< class Key, class T, class Hash, class Pred, class Alloc >
180 template< class... Args >
182 {
185 }
186
187 template< class Key, class T, class Hash, class Pred, class Alloc >
188 template< class... Args >
190 {
193 }
194
195 template< class Key, class T, class Hash, class Pred, class Alloc >
197 {
199 return m_container.erase(pos);
200 }
201
202 template< class Key, class T, class Hash, class Pred, class Alloc >
206 return m_container.erase(pos);
207 }
209 template< class Key, class T, class Hash, class Pred, class Alloc >
211 {
213 return m_container.erase(first, last);
214 }
215
216 template< class Key, class T, class Hash, class Pred, class Alloc >
218 {
221 }
222
223 template<class Key, class T, class Hash, class Pred, class Alloc>
225 {
228 }
229
230 template< class Key, class T, class Hash, class Pred, class Alloc >
232 {
235 }
236
237 template< class Key, class T, class Hash, class Pred, class Alloc >
239 {
242 }
243
244 template< class Key, class T, class Hash, class Pred, class Alloc >
246 {
247 // The element access may insert a default element and can trigger a rehash.
250 }
251
252 template< class Key, class T, class Hash, class Pred, class Alloc >
254 {
257 }
258
259 template< class Key, class T, class Hash, class Pred, class Alloc >
261 {
264 }
265
266 template< class Key, class T, class Hash, class Pred, class Alloc >
268 {
271 }
272
273 template< class Key, class T, class Hash, class Pred, class Alloc >
275 {
278 }
279
280 template< class Key, class T, class Hash, class Pred, class Alloc >
282 {
285 }
286
287 template< class Key, class T, class Hash, class Pred, class Alloc >
288 bool unordered_map<Key,T,Hash,Pred,Alloc>::contains( const Key& key ) const
289 {
292 }
293
294 template< class Key, class T, class Hash, class Pred, class Alloc >
296 {
299 }
300
301 template< class Key, class T, class Hash, class Pred, class Alloc >
303 {
306 }
307
308 template< class Key, class T, class Hash, class Pred, class Alloc >
310 {
312 return m_container.begin();
313 }
314
315 template< class Key, class T, class Hash, class Pred, class Alloc >
317 {
319 return m_container.end();
320 }
321
322 template< class Key, class T, class Hash, class Pred, class Alloc >
324 {
326 return m_container.begin();
327 }
328
329 template< class Key, class T, class Hash, class Pred, class Alloc >
331 {
333 return m_container.end();
334 }
336 template< class Key, class T, class Hash, class Pred, class Alloc >
338 {
341 }
342
343 template< class Key, class T, class Hash, class Pred, class Alloc >
347 return m_container.cend();
348 }
349
350 template< class Key, class T, class Hash, class Pred, class Alloc >
351 bool unordered_map<Key,T,Hash,Pred,Alloc>::empty() const noexcept
354 return m_container.empty();
355 }
356
357 template< class Key, class T, class Hash, class Pred, class Alloc >
359 {
361 return m_container.max_size();
362 }
363} // namespace atermpp
364
365namespace atermpp::utilities {
366
367 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
370 {
371 if (this != &other)
372 {
375 }
376 return *this;
377 }
378
379 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
382 {
383 if (this != &other)
384 {
387 }
388 return *this;
390
391 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
393 {
394 if constexpr (ThreadSafe)
395 {
399 else
400 {
404 }
406
407 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
412
413 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
416 if constexpr (ThreadSafe)
417 {
419 {
421 // Re-check under the exclusive lock: another thread may have rehashed already.
422 if (rehash_is_needed())
423 {
425 }
426 }
427 }
428 else
429 {
434 }
437
438 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
444
445 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
446 template<typename ...Args>
448 {
449 if constexpr (ThreadSafe)
450 {
452 return m_container.find(args...);
453 }
454 return m_container.find(args...);
455 }
456
457 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
458 template<typename ...Args>
460 {
461 if constexpr (ThreadSafe)
462 {
464 return m_container.find(args...);
466 return m_container.find(args...);
468
469 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
472 {
473 // The element access may insert a default element and can trigger a rehash.
476 return m_container[key];
477 }
478
479 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
482 {
484 return m_container.at(key);
485 }
486
487 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
490 {
492 return m_container.count(key);
493 }
494
495 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
497 {
500 return m_container.insert(value);
501 }
502
503 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
504 template< class P >
506 {
509 return m_container.insert(std::forward<P>(value));
510 }
511
512 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
514 {
517 return m_container.insert(hint, std::move(value));
518 }
519
520 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
521 template< class P >
523 {
527 }
528
529 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
530 template< class InputIt >
532 {
536 }
537
538 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
540 {
544 }
545
546
547 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
548 template <class M>
550 {
554 }
555
556 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
557 template <class M>
559 {
563 }
564
565 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
566 template <class M>
568 {
572 }
573
574 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
575 template <class M>
577 {
581 }
582
583 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
584 template< class... Args >
586 {
589 return m_container.emplace(std::forward<Args>(args)...);
590 }
591
592 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
593 template <class... Args>
595 {
599 }
600
601 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
602 template< class... Args >
604 {
608 }
609
610 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
611 template< class... Args >
613 {
617 }
618
619 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
620 template< class... Args >
622 {
626 }
627
628 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
629 template< class... Args >
631 {
635 }
636
637 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
639 {
641 return m_container.erase(pos);
642 }
643
644 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
646 {
648 return m_container.erase(pos);
649 }
650
651 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
653 {
655 return m_container.erase(first, last);
656 }
657
658 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
660 {
662
663 // The underlying erase(key) returns void and requires the key to be present,
664 // so find first and report the number of erased elements as std::unordered_map does.
665 auto it = m_container.find(key);
666 if (it == m_container.end())
667 {
668 return 0;
669 }
671 return 1;
672 }
673
674 template<class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe>
676 {
679 }
680
681 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
683 {
685 return m_container.begin();
686 }
687
688 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
690 {
692 return m_container.end();
693 }
694
695 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
697 {
699 return m_container.begin();
700 }
701
702 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
704 {
706 return m_container.end();
707 }
708
709 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
711 {
713 return m_container.cbegin();
714 }
715
716 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
718 {
720 return m_container.cend();
721 }
722
723 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
725 {
727 return m_container.empty();
728 }
729
730 template< class Key, class T, class Hash, class Pred, class Alloc, bool ThreadSafe >
732 {
734 return m_container.max_size();
735 }
736} // namespace atermpp::utilities
737
738#endif // MCRL2_ATERMPP_STANDARD_CONTAINER_DETAIL_UNORDERED_MAP_IMPLEMENTATION_H
#define ATERM_POOL_STORAGE_TEMPLATES
atermpp::aterm create_nested_function(const std::string &function_name, const std::string &leaf_name, std::size_t number_of_arguments, std::size_t depth)
Create a nested function application f_depth. Where f_0 = c and f_i = f(f_i-1,...,...
atermpp::aterm create_nested_function(const std::string &function_name, const std::string &leaf_name, std::size_t depth)
Create a nested function application f_depth. Where f_0 = c and f_i = f(f_i-1,...,...
void benchmark_threads(std::size_t number_of_threads, F f)
Run the given function f on number_of_threads threads (including the main thread) and report the elap...
The aterm_core base class that provides protection of the underlying shared terms.
Definition aterm_core.h:151
aterm_core & operator=(aterm_core &&other) noexcept
Move assignment operator.
~aterm_core() noexcept
Standard destructor.
aterm_core & operator=(const aterm_core &other) noexcept
Assignment operator.
aterm_core(const aterm_core &other) noexcept
Copy constructor.
aterm_core(aterm_core &&other) noexcept
Move constructor.
aterm_core() noexcept
Default constructor.
aterm_core & assign(const aterm_core &other, detail::thread_aterm_pool &pool) noexcept
Assignment operator, to be used if busy and forbidden flags are explicitly available.
aterm_core & unprotected_assign(const aterm_core &other) noexcept
Assignment operator, to be used when the busy flags do not need to be set.
aterm_core(const detail::_aterm *t) noexcept
Constructor based on an internal term data structure. This is not for public use.
aterm(aterm &&other) noexcept=default
aterm()
Default constructor.
Definition aterm.h:51
aterm & operator=(const aterm &other) noexcept=default
aterm(const aterm &other) noexcept=default
This class has user-declared copy constructor so declare default copy and move operators.
aterm(detail::_term_appl *t)
Constructor.
Definition aterm.h:33
aterm & operator=(aterm &&other) noexcept=default
aterm(const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Constructor that provides an aterm based on a function symbol and forward iterator providing the argu...
Definition aterm.h:70
This class allocates _aterm_appl objects where the size is based on the arity of the function symbol.
Definition aterm.h:113
T * allocate_args(const function_symbol &symbol, unprotected_aterm_core *)
Allocates space for an _aterm_appl where the arity is given by the function symbol.
Definition aterm.h:143
T * allocate_args(const function_symbol &symbol, ForwardIterator, ForwardIterator)
Allocates space for an _aterm_appl where the arity is given by the function symbol.
Definition aterm.h:134
std::allocator< char > m_packed_allocator
Definition aterm.h:182
static constexpr std::size_t term_appl_size(std::size_t arity)
Definition aterm.h:116
void destroy(T *element)
Specialize destroy for _aterm_appl to only destroy the function symbol. The reference count for the a...
Definition aterm.h:158
constexpr std::size_t capacity() const
Definition aterm.h:177
void deallocate(T *element, std::size_t)
Definition aterm.h:167
constexpr bool has_free_slots() const noexcept
Definition aterm.h:179
constexpr std::size_t consolidate() const noexcept
Definition aterm.h:178
void construct(T *element, const function_symbol &symbol, ForwardIterator begin, ForwardIterator end)
Constructs an _aterm_appl with arguments taken from begin, the arity is given by the function symbol.
Definition aterm.h:152
This class stores a term followed by N arguments. Where N should be equal to the arity of the functio...
Definition aterm.h:34
_aterm_appl(const function_symbol &symbol, Iterator it, Iterator end, bool)
constructs a term application with the given symbol and its arguments from the iterator.
Definition aterm.h:74
_aterm_appl(const function_symbol &sym, const Terms &... arguments)
Constructs a term application with the given symbol and arguments.
Definition aterm.h:39
_aterm_appl(const function_symbol &sym, std::array< unprotected_aterm_core, N > arguments)
Constructs a term application with the given symbol and arguments.
Definition aterm.h:65
std::array< unprotected_aterm_core, N > m_arguments
Definition aterm.h:102
operator _aterm_appl< 1 > &()
Convert any known number of arguments aterm<N> to the default _aterm_appl.
Definition aterm.h:96
_aterm_appl(const function_symbol &sym, Iterator it, Iterator end)
constructs a term application with the given symbol and an iterator where the number of elements is e...
Definition aterm.h:50
const aterm_core & arg(std::size_t index) const
Definition aterm.h:90
The underlying integer term that actually carries the integer data.
Definition aterm_int.h:21
std::size_t value() const noexcept
Definition aterm_int.h:29
_aterm_int(std::size_t value)
Constructs the underlying term from a given value.
Definition aterm_int.h:24
This is the class to which an aterm points.
Definition aterm_core.h:48
bool is_marked() const
Check if the term is already marked.
Definition aterm_core.h:73
_aterm(const function_symbol &symbol)
Create a term from a function symbol.
Definition aterm_core.h:51
function_symbol m_function_symbol
Definition aterm_core.h:79
const function_symbol & function() const noexcept
Definition aterm_core.h:55
void mark() const
Mark this term to be garbage collected.
Definition aterm_core.h:61
void unmark() const
Remove the mark from a term.
Definition aterm_core.h:67
Stores the data for a function symbol (name, arity) pair.
const std::string & name() const noexcept
bool operator==(const _function_symbol &f) const noexcept
std::size_t arity() const noexcept
aterm_allocator(aterm_allocator &&)=default
T * allocate(size_type n, const void *hint=nullptr)
aterm_allocator & operator=(aterm_allocator &&)=default
std::function< std::size_t()> size_func
std::function< void(term_mark_stack &)> mark_func
aterm_container(std::function< void(term_mark_stack &)> mark_func, std::function< std::size_t()> size_func)
void mark(term_mark_stack &todo) const
Mark all terms held by this container.
This class provides for all types of term storage. It also provides garbage collection via its mark a...
bool create_appl_iterator(aterm &term, const function_symbol &sym, TermConverter converter, InputIterator begin, InputIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
constexpr bool is_dynamic_storage() const
std::vector< callback_pair > m_deletion_hooks
This array stores creation, resp deletion, hooks for function symbols.
void print_performance_stats(const char *identifier) const
Prints various performance statistics for this storage.
bool create_appl(aterm &term, const function_symbol &sym, const Terms &... arguments)
Creates a function application with the given function symbol and arguments.
bool create_int(aterm &term, std::size_t value)
Creates a integral term with the given value.
bool create_appl_iterator(aterm &term, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
void resize_if_needed()
Resizes the hash table if necessary.
bool verify_sweep()
Check that all arguments of a term application are marked properly.
unordered_set m_term_set
This is the set of term pointers to keep the terms unique.
void add_deletion_hook(function_symbol sym, term_callback callback)
Add a callback that is triggered whenever a term with the given function symbol is destroyed.
aterm_pool & m_pool
The pool that this storage belongs to.
bool create_appl_dynamic(aterm &term, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
std::size_t capacity() const noexcept
bool emplace(aterm_core &term, Args &&... args)
Inserts a term constructed by the given arguments, checks for existing term.
iterator destroy(iterator it)
Removes an element from the unordered set and deallocates it.
void call_deletion_hook(unprotected_aterm_core term)
Calls the deletion hook attached to the function symbol of this term.
aterm_pool_storage(const aterm_pool_storage &other)
A fake copy constructor to fix the issues with GCC 4 and 5.
mcrl2::utilities::cache_metric m_term_metric
Count the number of times a term has been found in or is added to the set.
bool create_appl_dynamic(aterm &term, const function_symbol &sym, TermConverter converter, InputIterator begin, InputIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
bool verify_term(const _aterm &term)
Verify that the given term was constructed properly.
bool verify_mark()
Check that all arguments of a term application are marked properly.
bool create_term(aterm &term, const function_symbol &sym)
Creates a term with the given function symbol.
bool resize_is_needed() const
Check whether resizing the hash table is needed.
void sweep()
sweep Destroys all terms that are not reachable. Requires that mark() was called first.
The interface for the term library. Provides the storage of of all classes of terms.
Definition aterm_pool.h:83
const function_symbol & as_int() noexcept
Definition aterm_pool.h:121
void enable_resize(bool enable)
Enable automatic hash table resizing when passing true and disable otherwise.
Definition aterm_pool.h:136
bool create_appl(aterm &term, const function_symbol &sym, const Terms &... arguments)
Creates a function application with the given function symbol and arguments.
std::atomic< bool > m_enable_garbage_collection
Definition aterm_pool.h:225
function_symbol create_function_symbol(const std::string &name, std::size_t arity, bool check_for_registered_functions=false)
Creates a function symbol pair (name, arity).
function_symbol create_function_symbol(std::string &&name, std::size_t arity, bool check_for_registered_functions=false)
Creates a function symbol pair (name, arity).
void remove_thread_aterm_pool(thread_aterm_pool_interface &pool)
Remove thread specific aterm pool.
std::vector< thread_aterm_pool_interface * > m_thread_pools
The set of local aterm pools.
Definition aterm_pool.h:199
bool create_int(aterm &term, std::size_t val)
Creates a integral term with the given value.
function_symbol_pool m_function_symbol_pool
Storage for the function symbols.
Definition aterm_pool.h:202
void collect_impl(mcrl2::utilities::shared_mutex &mutex)
Collect garbage on all storages.
bool resize_is_needed(mcrl2::utilities::shared_mutex &shared) const
Resizes all storages if necessary.
arbitrary_function_application_storage m_appl_dynamic_storage
Storage for term_appl with a dynamic number of arguments larger than 7.
Definition aterm_pool.h:220
const function_symbol & as_empty_list() noexcept
Definition aterm_pool.h:127
const function_symbol & as_list() noexcept
Definition aterm_pool.h:124
aterm_core m_empty_list
Represents an empty list.
Definition aterm_pool.h:233
void print_performance_statistics() const
Prints various performance statistics for the term pool.
std::atomic< long > m_count_until_collection
Track the number of terms destroyed and reduce the freelist.
Definition aterm_pool.h:223
void register_thread_aterm_pool(thread_aterm_pool_interface &pool)
Register a thread specific aterm pool.
bool create_term(aterm &term, const function_symbol &sym)
Creates a term with the given function symbol.
void collect(mcrl2::utilities::shared_mutex &mutex)
Force garbage collection on all storages.
bool create_appl_dynamic(aterm &term, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
bool create_appl_dynamic(aterm &term, const function_symbol &sym, ATermConverter convert_to_aterm, InputIterator begin, InputIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
aterm & empty_list() noexcept
Definition aterm_pool.h:118
mcrl2::utilities::shared_mutex m_shared_mutex
Automatic hash table resizing is enabled.
Definition aterm_pool.h:230
void add_deletion_hook(function_symbol sym, term_callback callback)
Add a callback that is triggered whenever a term with the given function symbol is destroyed.
function_symbol_pool & get_symbol_pool()
Definition aterm_pool.h:138
integer_term_storage m_int_storage
Storage for integral terms.
Definition aterm_pool.h:205
std::atomic< bool > m_enable_resize
Garbage collection is enabled.
Definition aterm_pool.h:227
void created_term(mcrl2::utilities::shared_mutex &mutex, long &count_until_check)
Triggers garbage collection and resizing when conditions are met.
void resize_if_needed(mcrl2::utilities::shared_mutex &shared)
Resizes all storages if necessary.
void enable_garbage_collection(bool enable)
Enable garbage collection when passing true and disable otherwise.
Definition aterm_pool.h:133
std::size_t capacity() const noexcept
The number of terms that can be stored without resizing.
This class stores a set of function symbols.
void sweep()
Collect all garbage function symbols.
void deregister(const std::string &prefix)
Restore the index back to index before registering this prefix.
bool resize_is_needed() const
Check whether a resize is needed.
std::shared_ptr< std::size_t > register_prefix(const std::string &prefix)
void resize_if_needed()
Resize the function symbol pool if necessary.
const function_symbol & as_int() noexcept
unordered_set m_symbol_set
Stores the underlying function symbols.
const function_symbol & as_empty_list() noexcept
void create_helper(const std::string &name)
function_symbol create(const std::string &name, std::size_t arity, bool check_for_registered_functions=false)
Creates a function symbol pair (name, arity), returns a pointer to an existing element if this pair i...
std::size_t get_sufficiently_large_postfix_index(const std::string &prefix) const
Get an index such that no function symbol with name prefix + returned value and any value above it al...
std::size_t capacity() const noexcept
mcrl2::utilities::cache_metric m_function_symbol_metrics
Track the number of function symbols found in or added to the set.
function_symbol create(std::string &&name, std::size_t arity, bool check_for_registered_functions=false)
const function_symbol & as_list() noexcept
generic_aterm_container & operator=(const generic_aterm_container &)
generic_aterm_container(const generic_aterm_container &)=delete
generic_aterm_container & operator=(generic_aterm_container &&) noexcept
generic_aterm_container(generic_aterm_container &&)=delete
generic_aterm_container(const Container &container)
Constructor. Registers the container with the GC.
void mark()
Mark the terms created by this thread to prevent them being garbage collected.
Definition aterm_pool.h:47
thread_aterm_pool_interface(aterm_pool &pool, std::function< void()> mark_function, std::function< void()> print_function, std::function< std::size_t()> protection_set_size_function)
Definition aterm_pool.h:237
void print_local_performance_statistics() const
Print performance statistics for data stored for this thread.
Definition aterm_pool.h:53
std::function< std::size_t()> m_protection_set_size_function
Definition aterm_pool.h:71
void collect()
Triggers a global garbage collection.
void deregister_container(aterm_container *variable)
Removes the given container from the active variables.
void register_container(aterm_container *variable)
Consider the given container when marking underlying terms.
void absorb(mcrl2::utilities::hashtable< aterm_core * > &variables, mcrl2::utilities::hashtable< aterm_container * > &containers)
Transfers the surviving variables and containers of a pool that is being destroyed into this pool.
mcrl2::utilities::shared_mutex m_shared_mutex
Keeps track of pointers to all existing aterm variables and containers.
void create_int(aterm &term, std::size_t val)
thread_aterm_pool_interface m_thread_interface
The registered thread aterm pool.
void create_appl(aterm &term, const function_symbol &sym, const Terms &... arguments)
thread_aterm_pool(aterm_pool &global_pool)
void deregister_variable(aterm_core *variable)
Removes the given variable from the active variables.
void create_term(aterm &term, const function_symbol &sym)
bool is_shared_locked()
Returns true iff we are in a shared section.
mcrl2::utilities::hashtable< detail::aterm_container * > * m_containers
void create_appl_dynamic(aterm &term, const function_symbol &sym, ATermConverter convert_to_aterm, InputIterator begin, InputIterator end)
function_symbol create_function_symbol(std::string &&name, std::size_t arity, bool check_for_registered_functions=false)
mcrl2::utilities::hashtable< aterm_core * > * m_variables
void resize()
Resizes the global hash tables when needed.
std::stack< std::reference_wrapper< _aterm > > m_todo
A reusable todo stack.
void create_appl_dynamic(aterm &term, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
void register_variable(aterm_core *variable)
Consider the given variable when marking underlying terms.
function_symbol create_function_symbol(const std::string &name, std::size_t arity, bool check_for_registered_functions=false)
mcrl2::utilities::lock_guard lock()
Acquire an exclusive lock.
void create_appl_index(aterm &term, const function_symbol &sym, const Terms &... arguments)
mcrl2::utilities::shared_guard lock_shared()
Acquire a shared lock on this thread aterm pool.
void swap(function_symbol &f) noexcept
Swap this function with its argument.
bool operator!=(const function_symbol &f) const
Inequality test.
function_symbol & operator=(const function_symbol &other) noexcept=default
function_symbol(function_symbol &&other) noexcept=default
bool operator>=(const function_symbol &f) const
Comparison operation.
bool operator==(const function_symbol &f) const
Equality test.
function_symbol(detail::_function_symbol::ref &&f)
Constructor for internal use only.
bool operator<(const function_symbol &f) const
Comparison operation.
function_symbol(const function_symbol &other) noexcept=default
This class has non-trivial destructor so declare default copy and move operators.
void destroy()
Calls the function symbol pool to free our used memory.
function_symbol & operator=(function_symbol &&other) noexcept=default
std::size_t arity() const
Return the arity (number of arguments) of the function symbol (function_symbol).
detail::_function_symbol::ref m_function_symbol
The shared reference to the underlying function symbol.
const std::string & name() const
Return the name of the function_symbol.
bool operator>(const function_symbol &f) const
Comparison operation.
bool operator<=(const function_symbol &f) const
Comparison operation.
Iterator for term_appl.
term_appl_iterator operator++(int)
Postfix increment.
bool operator==(const term_appl_iterator &other) const
Equality of iterators.
term_appl_iterator operator-(ptrdiff_t n) const
Decrease by a constant value.
term_appl_iterator & operator--()
Prefix decrement.
ptrdiff_t operator-(const term_appl_iterator &other) const
The negative distance from this to the other iterator.
term_appl_iterator & operator++()
Prefix increment.
term_appl_iterator & operator-=(difference_type n)
Decrease the iterator with n steps.
const Term & operator[](difference_type n) const
The dereference operator.
term_appl_iterator operator+(ptrdiff_t n) const
Increase by a constant value.
friend term_appl_iterator< Derived > detail::aterm_appl_iterator_cast(term_appl_iterator< Base > a)
term_appl_iterator operator--(int)
Post decrement an iterator.
const Term * operator->() const
Dereference the current iterator.
term_appl_iterator & operator+=(difference_type n)
Increase the iterator with n steps.
const Term & operator*() const
The dereference operator.
term_appl_iterator(const Term *t)
Constructor.
ptrdiff_t distance_to(const term_appl_iterator &other) const
Provide the distance to the other iterator.
A unordered_map class in which aterms can be stored.
An unprotected term does not change the reference count of the shared term when it is copied or moved...
Definition aterm_core.h:34
bool type_is_list() const noexcept
Dynamic check whether the term is an aterm_list.
Definition aterm_core.h:75
void swap(unprotected_aterm_core &t) noexcept
Swaps this term with its argument.
Definition aterm_core.h:120
bool operator==(const unprotected_aterm_core &t) const
Comparison operator.
Definition aterm_core.h:87
unprotected_aterm_core() noexcept
Default constuctor.
Definition aterm_core.h:43
bool type_is_appl() const noexcept
Dynamic check whether the term is an aterm.
Definition aterm_core.h:57
bool defined() const
Returns true if this term is not equal to the term assigned by the default constructor of aterms,...
Definition aterm_core.h:111
friend detail::_aterm * detail::address(const unprotected_aterm_core &t)
const detail::_aterm * m_term
Definition aterm_core.h:38
const function_symbol & function() const
Yields the function symbol in an aterm.
Definition aterm_core.h:129
bool type_is_int() const noexcept
Dynamic check whether the term is an aterm_int.
Definition aterm_core.h:65
unprotected_aterm_core(const detail::_aterm *term) noexcept
Constructor.
Definition aterm_core.h:49
File output class.
Definition logger.h:329
void output(const log_level_t level, const time_t timestamp, const std::string &msg, const bool print_time_information) override
Definition logger.h:359
static void set_stream(FILE *stream)
Definition logger.h:345
~file_output() override=default
static std::atomic< FILE * > & get_stream()
Obtain the underlying stream used to print to a file.
Definition logger.h:332
static std::string format(const log_level_t level, const time_t timestamp, const std::string &msg, const bool print_time_information)
Format msg,.
Definition logger.h:270
Mixin that takes care of formatting of a message.
Definition logger.h:284
static std::atomic< std::size_t > & caret_pos()
Definition logger.h:303
static std::atomic< bool > & last_message_ended_with_newline()
Records whether the last message that was printed ended with a new line.
Definition logger.h:289
static std::atomic< std::size_t > & last_caret_pos()
Definition logger.h:310
static std::string format(log_level_t level, time_t timestamp, const std::string &msg, bool print_time_information)
Prefix each line in s with some extra information. The things that are added are:
Definition logger.cpp:33
static std::atomic< bool > & last_message_was_status()
Definition logger.h:296
Class for logging messages.
Definition logger.h:129
static void clear_report_time_info()
Indicate that timing information should not be printed.
Definition logger.h:241
static void unregister_output_policy(output_policy &policy)
Unregister output policy.
Definition logger.h:191
static void set_report_time_info()
Indicate that timing information should be printed.
Definition logger.h:235
log_level_t m_level
The loglevel of the current message.
Definition logger.h:136
static std::set< output_policy * > & output_policies()
Output policies.
Definition logger.h:156
static log_level_t get_reporting_level()
Get reporting level, i.e. the level that is in effect on the current thread: the override of the curr...
Definition logger.h:228
static void set_reporting_level(const log_level_t level)
Set reporting level.
Definition logger.h:210
std::ostringstream & get()
Get access to the stream provided by the logger.
Definition logger.h:254
logger(const log_level_t l)
Default constructor.
Definition logger.h:164
static void clear_output_policies()
Clear all output policies.
Definition logger.h:202
time_t m_timestamp
Timestamp of the current message.
Definition logger.h:139
static void register_output_policy(output_policy &policy)
Register output policy.
Definition logger.h:184
static std::atomic< bool > & m_print_time_information()
An indication whether time information should be printed.
Definition logger.h:148
~logger()
Destructor; flushes output. Flushing during destruction is important to confer thread safety to the l...
Definition logger.h:174
static bool get_report_time_info()
Get whether timing information is printed.
Definition logger.h:248
static std::atomic< log_level_t > & log_level()
Definition logger.h:141
static std::optional< log_level_t > & thread_reporting_level()
The reporting level override of the current thread. When it has a value, it takes precedence over the...
Definition logger.h:218
std::ostringstream m_os
Stream that is printed to internally Collects the full debug message that we are currently printing.
Definition logger.h:133
Interface class for output policy.
Definition logger.h:102
virtual void output(log_level_t level, time_t timestamp, const std::string &msg, bool print_time_information)=0
Output message.
virtual ~output_policy()=default
Destructor.
output_policy()=default
Constructor.
Helper that temporarily limits the reporting level of the current thread to the given level.
Definition logger.h:410
scoped_reporting_level(const log_level_t level)
Report at the given level on the current thread until this object is destroyed, regardless of the glo...
Definition logger.h:414
std::optional< log_level_t > m_saved_level
Definition logger.h:428
~scoped_reporting_level()
Restores the reporting level that was active on this thread before this object was constructed.
Definition logger.h:422
Iterator over thread-local values.
void advance_to_next_present()
Scan forward from the current (bucket, index) position to the next present entry, caching it in m_cur...
Iter(const ThreadLocal *tl, bool begin)
bool operator!=(const Iter &other) const
bool operator==(const Iter &other) const
Per-object thread-local storage container.
const T * get_or(F &&create)
Get the thread-local value for the current thread, or create it if it doesn't exist.
static void deallocate_bucket(Entry *bucket_ptr, std::size_t)
Helper to deallocate a bucket.
static Entry * allocate_bucket(std::size_t size)
Helper to allocate a bucket.
T * get_or_mut(F &&create)
Get a mutable pointer to the thread-local value for the current thread, or create it.
const T * get() const
Get the thread-local value for the current thread, if it exists.
std::array< std::atomic< Entry * >, BUCKETS > buckets
const T * get_inner(const detail::ThreadBucket &thread) const
Get the value for the given thread, if it exists.
const T * get_or_try(F &&create)
Get the thread-local value for the current thread, or create it if it doesn't exist.
static constexpr std::size_t POINTER_WIDTH
Iter end() const
Get the end iterator.
static constexpr std::size_t BUCKETS
void for_each_mut(const F &func)
Apply func to every present thread-local value via a mutable reference.
Iter begin() const
Get an iterator over all thread-local values.
std::atomic< std::size_t > values_count
void clear()
Clear all thread-local values.
std::size_t size() const
Get the number of thread-local values (approximate).
~ThreadLocal()
Destructor that cleans up all allocated buckets.
ThreadLocal()
Create a new empty ThreadLocal container.
const T * insert(const detail::ThreadBucket &thread, T value)
Insert a value for the given thread.
Fixed-size block allocator compatible with the STL allocator interface.
static Entry * sentinel_ptr() noexcept
bool refill_local_free(LocalState &state)
std::size_t consolidate()
Removes empty blocks and returns the number of blocks removed.
T * allocate_new_block(LocalState &state)
void for_each_local_state(const F &func)
static constexpr std::size_t N
T * allocate(size_type n, const void *hint=nullptr)
A helper class to keep track of the number of hits and misses for cache-like data structures.
void reset()
Resets the cache counters.
void miss()
Should be called when searching the cache was a miss.
void hit()
Should be called when searching the cache was a hit.
Iterator over all keys in a bucket list.
bool operator!=(const key_iterator &it) const noexcept
reference operator*() const
Only allowed whenever it points to an actual node (not before_begin or end)
bool operator==(const key_iterator &it) const noexcept
operator key_iterator() const
Implicit conversion to const_iterator.
pointer operator->() const
Only allowed whenever it points to an actual node (not before_begin or end)
const node_base * get_node() const noexcept
The nodes of the bucket list without carrying any additional informations. Used to make no different ...
Definition bucket_list.h:50
std::atomic< node_base * > m_next
Pointer to the next node.
Definition bucket_list.h:73
void set_next(node_base *next) noexcept
Set the next pointer to the given next pointer.
Definition bucket_list.h:66
bool exchange(node_base *&expected, node_base *value)
Definition bucket_list.h:69
node(Args &&... args)
Constructs a key by using the given arguments.
Definition bucket_list.h:83
const Key & key() const noexcept
Definition bucket_list.h:89
This essentially implements the std::forward_list, with the difference that it does not own the nodes...
Definition bucket_list.h:44
void splice_after(const_iterator pos, bucket_list &other)
Moves the elements from other into this bucket after the given position.
iterator erase_after(NodeAllocator &allocator, const_iterator it)
Removes the element after the given iterator from the list. The returned iterator.
void clear(NodeAllocator &allocator)
Empties the bucket list.
const_iterator before_begin() const
std::pair< iterator, bool > emplace_front_unique(NodeAllocator &allocator, const Equals &equals, Args &&...args)
Constructs an element using the allocator with the given arguments and insert it in the front of the ...
void splice_front(const_iterator pos, bucket_list &other)
Moves the first node from the given bucket into this bucket after the given position.
node_base m_head
The first node in the bucket list.
void emplace_front(NodeAllocator &allocator, Args &&...args)
Constructs an element using the allocator with the given arguments and insert it in the front.
A set that assigns each element an unique index.
Definition hashtable.h:25
iterator end()
End of the forward iterator.
Definition hashtable.h:65
size_type size() const
The number of elements in the indexed set.
Definition hashtable.h:138
iterator end() const
End of the forward iterator.
Definition hashtable.h:78
void clear()
Clears the indexed set by removing all its elements. It is not guaranteed that the memory is released...
Definition hashtable.h:70
const_iterator crend() const
End of the reverse const_iterator.
Definition hashtable.h:114
iterator find(const key_type &key)
Find the given key and returns an iterator to that position.
Definition hashtable.h:157
iterator rbegin()
Reverse iterator going through the elements in the set from the largest to the smallest index.
Definition hashtable.h:96
void rehash(std::size_t size)
Resizes the hash table to the given power of two size.
Definition hashtable.h:22
hashtable(std::size_t initial_hashtable_size, const hasher &hash=hasher(), const key_equal &equals=key_equal())
Constructor of an empty index set. Starts with a hashtable of the indicated size.
Definition hashtable.h:58
void resize()
Resize the hashtable. This is not done automatically.
Definition hashtable.h:84
std::size_t get_index(const key_type &key)
Definition hashtable.h:173
hashtable()
Constructor of an empty indexed set. Starts with a hashtable of size 128.
Definition hashtable.h:52
const_iterator cbegin() const
const_iterator going through the elements in the set numbered from zero upwards.
Definition hashtable.h:84
size_type m_buckets_mask
Always equal to m_hashtable.size() - 1.
Definition hashtable.h:162
bool must_resize()
Check whether the hashtable must be resized. This is not automatic and must be done explicitly.
Definition hashtable.h:78
iterator begin()
Forward iterator which runs through the elements from the lowest to the largest number.
Definition hashtable.h:59
std::pair< iterator, bool > insert(const key_type &key)
Insert a key in the indexed set and return its index.
Definition hashtable.h:90
const_iterator crbegin() const
Reverse const_iterator going through the elements from the highest to the lowest numbered element.
Definition hashtable.h:108
std::vector< Key > m_hashtable
Definition hashtable.h:154
std::size_t m_number_of_elements
Definition hashtable.h:159
iterator rend()
End of the reverse iterator.
Definition hashtable.h:102
iterator begin() const
Forward iterator which runs through the elements from the lowest to the largest number.
Definition hashtable.h:72
const_iterator cend() const
End of the forward const_iterator.
Definition hashtable.h:90
iterator erase(const key_type &key)
Erases the key assuming that this key is present in the hashtable..
Definition hashtable.h:129
A set that assigns each element an unique index.
Definition indexed_set.h:31
void resize_hashtable()
Resizes the hash table to twice its current size.
std::vector< shared_mutex > m_shared_mutexes
Mutex for the m_hashtable and m_keys data structures.
Definition indexed_set.h:37
indexed_set()
Constructor of an empty indexed set. Starts with a hashtable of size 128 and assumes one single threa...
iterator end(std::size_t thread_index=0)
End of the forward iterator.
std::pair< size_type, bool > insert(const key_type &key, std::size_t thread_index=0)
Insert a key in the indexed set and return its index.
detail::atomic_wrapper< size_t > m_next_index
m_next_index indicates the next index that
Definition indexed_set.h:42
reverse_iterator rbegin(std::size_t thread_index=0)
Reverse iterator going through the elements in the set from the largest to the smallest index.
const_reverse_iterator crbegin(std::size_t thread_index=0) const
Reverse const_iterator going through the elements from the highest to the lowest numbered element.
const key_type & at(size_type index) const
Returns a reference to the mapped value.
const_reverse_iterator crend(std::size_t thread_index=0) const
End of the reverse const_iterator.
const_iterator begin(std::size_t thread_index=0) const
Forward iterator which runs through the elements from the lowest to the largest number.
void clear(std::size_t thread_index=0)
Clears the indexed set by removing all its elements. It is not guaranteed that the memory is released...
iterator begin(std::size_t thread_index=0)
Forward iterator which runs through the elements from the lowest to the largest number.
const_iterator cbegin(std::size_t thread_index=0) const
const_iterator going through the elements in the set numbered from zero upwards.
indexed_set(std::size_t number_of_threads, std::size_t initial_hashtable_size, const hasher &hash=hasher(), const key_equal &equals=key_equal())
Constructor of an empty index set. Starts with a hashtable of the indicated size.
const_iterator find(const key_type &key, std::size_t thread_index=0) const
Provides an iterator to the stored key in the indexed set.
size_type index(const key_type &key, std::size_t thread_index=0) const
Returns a reference to the mapped value.
const key_type & operator[](size_type index) const
Operator that provides a const reference at the position indicated by index.
reverse_iterator rend(std::size_t thread_index=0)
End of the reverse iterator.
void reserve_indices(std::size_t thread_index)
Reserve indices that can be used. Doing this infrequently prevents obtaining an exclusive lock for th...
const_iterator end(std::size_t thread_index=0) const
End of the forward iterator.
std::size_t put_in_hashtable(const Key &key, std::size_t value, std::size_t &new_position)
Inserts the given (key, n) pair into the indexed set.
size_type size(std::size_t thread_index=0) const
The number of elements in the indexed set.
indexed_set(std::size_t number_of_threads)
Constructor of an empty indexed set.
static constexpr size_type npos
Value returned when an element does not exist in the set.
Definition indexed_set.h:81
const_iterator cend(std::size_t thread_index=0) const
End of the forward const_iterator.
Inherit from this class to prevent it from being copyable.
Definition noncopyable.h:20
noncopyable & operator=(const noncopyable &)=delete
noncopyable & operator=(noncopyable &&)=default
noncopyable(const noncopyable &)=delete
noncopyable(noncopyable &&)=default
void unlock()
Release exclusive access.
std::atomic< bool > m_forbidden_flag
bool try_lock()
Try to obtain exclusive access without blocking on other exclusive locks.
std::atomic< bool > m_busy_flag
A boolean flag indicating whether this thread is working inside the global aterm pool.
void wait_for_busy() const
Waits for the busy flag to become false.
void lock_shared()
Acquires a shared lock on this mutex.
void unlock_shared()
Releases a shared lock on this mutex.
shared_mutex(const shared_mutex &other)
The copy/move constructor/assignment should not be called while any lock_guard or shared_guard is ali...
std::size_t m_lock_depth
It can happen that un/lock_shared calls are nested, so keep track of the nesting depth and only actua...
bool try_lock_shared()
Tries to acquire a shared lock on this mutex without blocking.
std::shared_ptr< shared_mutex_data > m_shared
shared_mutex & operator=(shared_mutex &&other) noexcept
shared_mutex & operator=(const shared_mutex &other)
shared_mutex(shared_mutex &&other) noexcept
void lock()
Obtain exclusive access, and stop all other threads that use this mutex.
Stores a reference count that can be incremented and decremented.
static void count_reference_count_changes()
Increment the number of reference count changes.
std::size_t reference_count() const
Obtain the reference count.
void increment_reference_count() const
Increment the reference count by one.
static std::atomic< std::size_t > & reference_count_changes()
Obtain the number of times that this reference count has changed.
void decrement_reference_count() const
Decrement the reference count by one.
A reference counted reference to a shared_reference_counted object.
bool operator==(const shared_reference< T > &other) const noexcept
Address equality operator.
shared_reference< T > & operator=(shared_reference< T > &&other) noexcept
Move assignment constructor.
bool defined() const
Check whether the shared_reference has a valid reference.
shared_reference() noexcept
The default constructor.
utilities::tagged_pointer< T > m_reference
shared_reference< T > & operator=(const shared_reference< T > &other) noexcept
Copy assignment constructor.
shared_reference(shared_reference< T > &&other) noexcept
Move constructor.
shared_reference(const shared_reference< T > &other) noexcept
Copy constructor.
shared_reference(T *reference) noexcept
Takes ownership of the passed reference, which means that its reference count is incremented.
void swap(shared_reference< T > &other) noexcept
Swaps *this with the other shared reference.
A pointer storage object that uses a least significant bit as a mark. Can be used by objects that are...
bool operator==(const tagged_pointer &other) const
bool operator==(std::nullptr_t) const
void untag() const
Remove the tag.
void swap(tagged_pointer< T > &other) noexcept
void tag() const
Apply a tag to the pointer that can be checked with tagged().
tagged_pointer & operator=(std::nullptr_t)
std::conditional_t< detail::GlobalThreadSafe, detail::atomic_wrapper< T * >, T * > m_pointer
A class for a map of keys to values in T based using the simple hash table set implementation.
unordered_map(std::size_t initial_size, const hasher &hash=hasher(), const key_equal &equals=key_equal())
Constructs an unordered_map that can store initial_size number of elements before resizing.
size_type bucket_size(size_type n) const noexcept
std::pair< iterator, bool > insert_or_assign(const Key &k, M &&obj)
local_iterator begin(size_type n)
iterator try_emplace(const_iterator, const Key &k, Args &&... args)
std::pair< iterator, bool > try_emplace(const key_type &key, Args &&... args)
std::pair< iterator, bool > insert(const value_type &pair)
Inserts elements.
iterator find(const Args &... args)
size_type count(const key_type &key) const
const_iterator begin() const
const_iterator cend() const
mapped_type & operator[](const key_type &key)
Provides access to the value associated with the given key, constructs a default value whenever the k...
const allocator_type & get_allocator() const noexcept
const_local_iterator cend(size_type n) const
size_type bucket(const key_type &key) const noexcept
void rehash(size_type number_of_buckets)
Resize the number buckets to at least number_of_buckets.
std::pair< iterator, bool > insert(const_iterator, const value_type &pair)
const_iterator cbegin() const
iterator try_emplace(const_iterator, Key &&k, Args &&... args)
iterator erase(const_iterator it)
const T & at(const key_type &key) const
Provides access to the value associated with the given key.
const_iterator find(const Args &... args) const
void erase(const key_type &key)
Erases elements.
const_iterator end() const
std::pair< iterator, bool > insert_or_assign(const_iterator, const Key &k, M &&obj)
allocator_type & get_allocator() noexcept
size_type max_size() const noexcept
bool empty() const noexcept
const_local_iterator end(size_type n) const
std::pair< iterator, bool > insert_or_assign(const_iterator, Key &&k, M &&obj)
Set m_set
The underlying set storing <key, value> pairs.
void reserve(size_type count)
Resizes the set to the given number of elements.
const_local_iterator cbegin(size_type n) const
iterator emplace_hint(const_iterator, Args &&... args)
const_local_iterator begin(size_type n) const
void max_load_factor(float factor)
size_type bucket_count() const noexcept
size_type capacity()
Number of elements that can be stored before rehash.
local_iterator end(size_type n)
void clear()
Clears the content.
size_type max_bucket_count() const noexcept
std::pair< iterator, bool > insert_or_assign(Key &&k, M &&obj)
std::pair< iterator, bool > emplace(Args &&... args)
static constexpr bool allow_transparent
True iff the hash and equals functions allow transparent lookup,.
An iterator over all elements in the unordered set.
unordered_set_iterator(bucket_it it, bucket_it end, key_it_type before_it, key_it_type key)
Construct an iterator over all keys passed in this bucket and all remaining buckets.
void goto_next_bucket()
Iterate to the next non-empty bucket.
unordered_set_iterator(bucket_it it)
Construct the end iterator.
unordered_set_iterator(bucket_it it, bucket_it end)
Construct the begin iterator (over all elements).
bool operator==(const unordered_set_iterator &other) const
bool operator!=(const unordered_set_iterator &other) const
A unordered_set with a subset of the interface of std::unordered_set that only stores a single pointe...
std::vector< std::mutex > m_bucket_mutexes
const_local_iterator cbegin(size_type n) const
const_local_iterator end(size_type n) const
void erase(const Args &... args)
Erases the given key_type(args...) from the unordered set.
const_iterator find_impl(size_type bucket_index, const Args &... args) const
Searches for the element in the given bucket.
const_local_iterator begin(size_type n) const
size_type count(const Args &... args) const
Counts the number of occurrences of the given key (1 when it exists and 0 otherwise).
size_type find_bucket_index(const Args &... args) const
std::vector< bucket_type > m_buckets
std::pair< iterator, bool > emplace_impl(size_type bucket_index, Args &&... args)
Inserts T(args...) into the given bucket, assumes that it did not exists before.
const_iterator cend() const
size_type bucket_count() const noexcept
bool empty() const noexcept
void erase_impl(const Args &... args)
Removes T(args...) from the set.
const_iterator begin() const
static constexpr bool allow_transparent
True iff the hash and equals functions allow transparent lookup,.
const_iterator end() const
std::conditional_t< ThreadSafe, std::atomic< size_type >, size_type > m_buckets_mask
Always equal to m_buckets.size() - 1.
size_type max_bucket_count() const noexcept
allocator_type & get_allocator() noexcept
std::pair< iterator, bool > emplace(Args &&... args)
Inserts an element Key(args...) into the set if it did not already exist.
void rehash_if_needed()
Resizes the hash table if necessary.
iterator find(const Args &... args)
bool rehash_is_needed() const
Checks whether a rehash is required.
const_iterator cbegin() const
std::conditional_t< ThreadSafe, std::atomic< size_type >, size_type > m_number_of_elements
The number of elements stored in this set.
size_type size() const noexcept
void clear()
Removes all elements from the set.
unordered_set(const unordered_set &set)
iterator erase(const_iterator it)
Erases the element pointed to by the iterator.
size_type max_size() const noexcept
void max_load_factor(float factor)
size_type bucket(const key_type &key) const noexcept
size_type capacity() const noexcept
local_iterator end(size_type n)
unordered_set(unordered_set &&other)=default
const_local_iterator cend(size_type n) const
const_iterator find(const Args &... args) const
Searches whether an object key_type(args...) occurs in the set.
void rehash(size_type number_of_buckets)
Resize the number buckets to at least number_of_buckets.
unordered_set & operator=(const unordered_set &set)
local_iterator begin(size_type n)
size_type bucket_size(size_type n) const noexcept
unordered_set(size_type bucket_count, const hasher &hash=hasher(), const key_equal &equals=key_equal())
Constructs an unordered_set that contains bucket_count number of buckets.
unordered_set & operator=(unordered_set &&other)=default
const allocator_type & get_allocator() const noexcept
void reserve(size_type count)
Resizes the set to the given number of elements.
Implements a simple stopwatch that starts on construction.
Definition stopwatch.h:17
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435
static constexpr bool EnableGarbageCollection
Enable garbage collection.
static constexpr bool EnableHashtableMetrics
Enable to print hashtable collision, size and number of buckets.
aterm_pool & g_term_pool()
obtain a reference to the global aterm pool.
void debug_print(std::ostream &o, const _aterm *t, std::size_t d=3)
bool equal_args(const _aterm_appl< 8 > &term, const Tp &... t)
Definition aterm_hash.h:383
void make_list_forward(term_list< Term > &result, Iter first, Iter last, ATermConverter convert_to_aterm)
Constructs a list starting from first to last. Each element is converted using the TermConverter.
static constexpr bool EnableCreationMetrics
Enable to obtain the percentage of terms found compared to allocated.
void make_list_forward(term_list< Term > &result, Iter first, Iter last, ATermConverter convert_to_aterm, ATermFilter aterm_filter)
Constructs a list traversing the iterator from first to last, putting the result in place in the vari...
function_symbol g_as_empty_list
term_list< Term > make_list_backward(Iter first, Iter last, ATermConverter convert_to_aterm, ATermFilter aterm_filter)
Constructs a list starting from first to last. The iterators are traversed backwards and each element...
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
std::size_t combine(const std::size_t hnr, const unprotected_aterm_core &term)
Auxiliary function to combine hnr with aterms.
Definition aterm_hash.h:160
void stop_gc_stress_thread()
Stop the background GC stress thread if it is running.
term_list< Term > make_list_forward(Iter first, Iter last, ATermConverter convert_to_aterm)
Constructs a list starting from first to last. Each element is converted using the TermConverter.
function_symbol g_as_list
static constexpr bool EnableGarbageCollectionMetrics
Enable to print garbage collection statistics.
std::array< unprotected_aterm_core, N > construct_arguments(InputIterator it, InputIterator end, TermConverter converter)
Construct the proxy where its arguments are given by applying the converter to each element in the it...
void start_gc_stress_thread()
Spawns a dedicated background thread that continuously triggers garbage collection.
term_list< Term > make_list_backward(Iter first, Iter last, ATermConverter convert_to_aterm)
Constructs a list starting from first to last. The iterators are traversed backwards and each element...
aterm_pool & g_aterm_pool_instance()
A reference to the global term pool storage.
thread_aterm_pool * g_main_thread_pool
Pointer to the main thread's pool; set on its first access and used by ~thread_aterm_pool to transfer...
void store_in_argument_array_(std::array< unprotected_aterm_core, N > &)
static constexpr bool EnableAggressiveGarbageCollection
Performs garbage collection intensively for testing purposes.
term_list< Term > make_list_forward(Iter first, Iter last, ATermConverter convert_to_aterm, ATermFilter aterm_filter)
Constructs a list starting from first to last. Each element is converted using the TermConverter and ...
function_symbol g_as_int
These function symbols are used to indicate integer, list and empty list terms.
std::size_t combine_args(std::size_t seed, const Tp &... t)
Definition aterm_hash.h:254
static constexpr bool EnableBlockAllocator
Enable the block allocator for terms.
mcrl2::utilities::shared_guard lock_shared_aterm_pool()
Acquires a shared lock on the global thread aterm pool.
static std::size_t xorshift(const std::size_t n, const std::size_t i)
Definition aterm_hash.h:277
void make_list_backward(term_list< Term > &result, Iter first, Iter last, ATermConverter convert_to_aterm, ATermFilter aterm_filter)
Construct a list iterating from the last to the first element. Result is put in the variable result.
void store_in_argument_array(std::array< unprotected_aterm_core, N > &argument_array, const Args &... args)
void make_list_backward(term_list< Term > &result, Iter first, Iter last, ATermConverter convert_to_aterm)
Constructs a list starting from first to last where the result is put in result.
static constexpr bool EnableVariableRegistrationMetrics
Keep track of the number of variables registered.
std::array< std::byte, sizeof(aterm_pool)> g_aterm_pool_storage
Storage for a global term pool that is not initialized.
term_appl_iterator< Derived > aterm_appl_iterator_cast(term_appl_iterator< Base > a)
This function can be used to translate an term_appl_iterator of one sort into another.
void mark_term(const _aterm &root, std::stack< std::reference_wrapper< _aterm > > &todo)
Marks a term and recursively all arguments that are not reachable.
static constexpr bool EnableGCStressThread
Spawns a dedicated background thread that continuously triggers garbage collection.
constexpr std::size_t DynamicNumberOfArguments
Indicates that the number of arguments is not known at compile time.
Definition aterm_hash.h:77
The main namespace for the aterm++ library.
void mark_term(const aterm_core &t, term_mark_stack &todo)
std::string pp(const atermpp::aterm &t)
Transform an aterm to an ascii string.
Definition aterm.h:329
void add_deletion_hook(const function_symbol &, term_callback)
Check for reasonably sized aterm (32 bits, 4 bytes) This check might break on perfectly valid archite...
void make_term_appl(Term &target, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Constructor an aterm in a variable based on a function symbol and an forward iterator providing the a...
Definition aterm.h:180
output_policy & default_output_policy()
The default output policy used by the logger.
Definition logger.h:379
log_level_t log_level_from_string(const std::string_view s)
Convert string to log level.
Definition logger.h:56
std::string_view log_level_to_string(const log_level_t level)
Convert log level to string This string is used to prefix messages in the logging output.
Definition logger.h:45
std::string format_time(const time_t *t)
Definition logger.cpp:18
std::set< output_policy * > initialise_output_policies()
Initialise the output policies. This returns the singleton set containing the default output policy.
Definition logger.h:388
log_level_t
Log levels that are supported.
Definition logger.h:31
bool mCRL2logEnabled(const log_level_t level)
Definition logger.h:396
static constexpr std::size_t PRIME_NUMBER
Definition indexed_set.h:32
std::size_t hash_combine(const std::size_t h1, const std::size_t h2)
static constexpr Sentinel EndIterator
A end of the iterator sentinel.
Definition bucket_list.h:24
static constexpr std::size_t EMPTY
in the hashtable we use the following constant to indicate free positions.
Definition indexed_set.h:26
static constexpr float max_load_factor
The load factor before the hash table is resized.
Definition indexed_set.h:30
auto allocate(Allocator &allocator, const Args &... args) -> decltype(allocator.allocate_args(args...))
A compile time check for allocate_args in the given allocator, calls allocate(1) otherwise.
Definition bucket_list.h:28
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
static constexpr std::size_t FreeChunkSize
Number of entries per shared free chunk handed between threads.
static constexpr std::size_t RESERVED
Definition indexed_set.h:28
std::size_t hash_combine_cheap(const std::size_t seed, const std::size_t hash_number)
Auxiliary function to combine seed with a hash number.
static constexpr std::size_t minimal_hashtable_size
Definition indexed_set.h:35
static const std::size_t STEP
The position on which the next hash entry is searched.
Definition indexed_set.h:23
static constexpr uintptr_t BlockAllocSentinel
Sentinel written to next to identify freed entries during consolidation.
static constexpr std::size_t RESERVATION_FRACTION
Definition indexed_set.h:39
std::size_t get_thread_id()
Get a unique identifier for the current thread.
float bytes_to_megabytes(std::size_t bytes)
std::string string_join(const Container &c, const std::string &separator)
Joins a sequence of strings. This is a replacement for boost::algorithm::join, since it gives stack o...
static constexpr std::size_t minimum_size
static constexpr long BucketsPerMutex
Number of buckets per mutex.
void number2string(std::size_t number, std::string &buffer, std::size_t start_position)
Convert a number to a string in the buffer starting at position start_position.
T * tag(const T *p)
Applies a tag to a pointer.
std::vector< std::string > split_paragraphs(const std::string &text)
Split a string into paragraphs.
std::string read_text(std::istream &in)
Read text from a stream.
bool tagged(const T *p)
void trim(std::string &text)
Remove all trailing and leading spaces from the input.
std::string regex_replace(const std::string &src, const std::string &dest, const std::string &text)
Regular expression replacement in a string.
T * pointer(const detail::atomic_wrapper< T * > &p)
T * pointer(const T *p)
std::string read_text(const std::string &filename, bool warn=false)
Read text from a file.
std::string word_wrap_text(const std::string &text, unsigned int max_line_length=78)
Apply word wrapping to a text.
bool is_numeric_string(const std::string &s)
Test if a string is a number.
std::string to_string(const T &x)
Transform parameter into string.
T * tag(const detail::atomic_wrapper< T * > &p)
std::vector< std::string > regex_split(const std::string &text, const std::string &sep)
Split a string using a regular expression separator.
std::string remove_comments(const std::string &text)
Remove comments from a text (everything from '' until end of line).
constexpr bool is_iterable_v
Definition type_traits.h:51
std::string trim_copy(const std::string &text)
Remove all trailing and leading spaces from the input.
static constexpr bool EnableLockfreeInsertion
Enables lockfree implementation of emplace.
std::string remove_whitespace(const std::string &text)
Removes whitespace from a string.
static constexpr bool EnableReferenceCountMetrics
Enable to count the number of reference count changes.
std::list< std::string > split_actions(const std::string &s)
Split a string on commas that occur outside parentheses.
std::string number2string(std::size_t number)
Convert a number to string.
std::vector< std::string > split(const std::string &line, const std::string &separators)
Split the text.
void print_performance_statistics(const T &unordered_set)
Prints various information for unordered_set like data structures.
bool tagged(const detail::atomic_wrapper< T * > &p)
constexpr bool is_iterator_v
Definition type_traits.h:54
void swap(atermpp::aterm &t1, atermpp::aterm &t2) noexcept
Swaps two term_applss.
Definition aterm.h:364
void swap(mcrl2::utilities::shared_reference< T > &a, mcrl2::utilities::shared_reference< T > &b) noexcept
void swap(atermpp::unprotected_aterm_core &t1, atermpp::unprotected_aterm_core &t2) noexcept
Swaps two aterms.
Definition aterm.h:351
int main(int argc, char *argv[])
#define MCRL2_DECLARE_STACK_ARRAY(NAME, TYPE, SIZE)
Declares a stack_array<TYPE> with the specified NAME that stores SIZE elements type TYPE.
Definition stack_array.h:98
#define MCRL2_STACK_ARRAY_NAME(NAME)
Define a (hopefully) unique name for the underlying reserved stack memory.
Definition stack_array.h:93
bool operator()(const _aterm &term, const function_symbol &symbol, const Args &... args) const noexcept
Definition aterm_hash.h:391
bool operator()(const _aterm &term, const function_symbol &symbol, std::array< unprotected_aterm_core, N > key) const noexcept
Returns true iff first and second are value-equivalent.
Definition aterm_hash.h:124
bool operator()(const _aterm &first, const _aterm &second) const noexcept
Definition aterm_hash.h:290
bool operator()(const _aterm &term, const function_symbol &symbol) const noexcept
Definition aterm_hash.h:315
bool operator()(const _aterm &term, const function_symbol &symbol, unprotected_aterm_core *arguments) const noexcept
Definition aterm_hash.h:321
Computes the hash of the given term.
Definition aterm_hash.h:100
std::size_t operator()(const function_symbol &symbol, const Args &... args) const noexcept
Definition aterm_hash.h:262
std::size_t operator()(const function_symbol &symbol, std::array< unprotected_aterm_core, N > key) const noexcept
Computes the hash of the given term.
Definition aterm_hash.h:84
std::size_t operator()(const function_symbol &symbol) const noexcept
Definition aterm_hash.h:187
std::size_t operator()(const _aterm &term) const noexcept
Implementation.
Definition aterm_hash.h:169
std::size_t operator()(const function_symbol &symbol, unprotected_aterm_core *arguments) const noexcept
Definition aterm_hash.h:194
Returns true iff the given term(s) or value are equivalent.
Definition aterm_hash.h:151
bool operator()(const _aterm_int &term, std::size_t value) const noexcept
Definition aterm_hash.h:401
bool operator()(const _aterm_int &first, const _aterm_int &second) const noexcept
Definition aterm_hash.h:396
Computes the hash of the integral term arguments.
Definition aterm_hash.h:112
std::size_t operator()(const _aterm_int &term) const noexcept
Definition aterm_hash.h:270
std::size_t operator()(std::size_t value) const noexcept
Definition aterm_hash.h:282
void operator()(Term &result, const Term &t) const
Definition aterm_list.h:35
const Term & operator()(const Term &t) const
Definition aterm_list.h:40
Term & operator()(Term &t) const
Definition aterm_list.h:45
True iff the given function symbols are equal to eachother or to the given key.
bool operator()(const _function_symbol &first, const _function_symbol &second) const noexcept
Computes the hash for given function symbol objects and for the function_symbol_key.
std::size_t operator()(const _function_symbol &symbol) const noexcept
Type trait to detect markable_aterm instantiations.
markable_aterm(Args &&... args) noexcept
markable_aterm(const stored_type &other) noexcept
markable_aterm(const markable_aterm &)=default
markable_aterm & operator=(const markable_aterm &)=default
markable_aterm & operator=(markable_aterm &&)=default
markable_aterm(markable_aterm &&)=default
The shared block list and free chunks. Protected by the allocator mutex.
BlockList(BlockList &&)=default
BlockList & operator=(BlockList &&)=default
std::vector< BlockEntry< T > * > free_chunks
Heads of linked chains of freed entries available for redistribution.
A fixed-size block of N entries linked in a singly-linked list.
std::array< BlockEntry< T >, N > data
Entry in the thread-local bucket.
std::atomic< bool > present
std::array< std::byte, sizeof(T)> value
Information about a thread's position in the bucket structure.
std::size_t bucket_size
Size of the current bucket.
ThreadBucket(std::size_t thread_id)
std::size_t bucket
Which bucket this thread's entry is in.
std::size_t index
Index within the bucket.
std::size_t id
Unique thread identifier.
Per-thread allocation state: current bump block and thread-local freelist.
std::size_t bump_offset
N or greater means the block is exhausted.
atomic_wrapper & operator=(const atomic_wrapper< T > &other)
atomic_wrapper(const atomic_wrapper< T > &other)
No-op mutex used when ThreadSafe=false.
Checks whether condition holds for all types passed as variadic template.
Definition type_traits.h:43
A typetrait that is std::true_type iff std::begin() and std::end() can be called on type T.
Definition type_traits.h:22
A typetrait that is std::true_type iff the given type has the iterator traits.
Definition type_traits.h:38
std::mutex mutex
Mutex for adding/removing shared_guards.
void unregister_mutex(shared_mutex *shared_mutex)
void register_mutex(shared_mutex *shared_mutex)
Adds a shared mutex to the data.
std::vector< shared_mutex * > other
The list of other mutexes.
bool operator()(const value_type &first, const U &key, const V &...) const
bool operator()(const value_type &first, const value_type &second) const
std::size_t operator()(const U &key, const V &...) const
std::size_t operator()(const value_type &pair) const
std::size_t operator()(const atermpp::aterm &t) const
Definition aterm.h:373
std::size_t operator()(const atermpp::aterm_core &t) const
Definition aterm_hash.h:63
std::size_t operator()(const atermpp::detail::_aterm *term) const
Definition aterm_hash.h:29
std::size_t operator()(const atermpp::detail::_function_symbol &f) const
std::size_t operator()(const atermpp::detail::markable_aterm< T > &t) const
std::size_t operator()(const atermpp::function_symbol &f) const
std::size_t operator()(const atermpp::unprotected_aterm_core &term) const
Definition aterm_hash.h:52
std::size_t operator()(const mcrl2::utilities::tagged_pointer< T > &p) const
std::size_t operator()(const std::pair< X, Y > &p) const
std::size_t operator()(const std::vector< X > &v) const
Union entry: active as value while live, as next while on a freelist.
#define INDEXED_SET
Definition indexed_set.h:49
#define INDEXED_SET_TEMPLATE
Definition indexed_set.h:48
#define MCRL2_UNORDERED_MAP_CLASS
#define MCRL2_UNORDERED_MAP_TEMPLATES
#define MCRL2_UNORDERED_SET_CLASS
#define MCRL2_UNORDERED_SET_TEMPLATES