mCRL2
Loading...
Searching...
No Matches
aterm_hash.h
Go to the documentation of this file.
1// Author(s): 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
10#ifndef MCRL2_ATERMPP_DETAIL_ATERM_HASH_H_
11#define MCRL2_ATERMPP_DETAIL_ATERM_HASH_H_
12
13#include "mcrl2/atermpp/detail/aterm.h"
14#include "mcrl2/atermpp/detail/aterm_int.h"
15#include "mcrl2/atermpp/detail/function_symbol_hash.h"
16#include "mcrl2/utilities/hash_utility.h"
17#include "mcrl2/utilities/detail/memory_utility.h"
18
19#include <cstdint>
20#include <functional>
21
22namespace std
23{
24
25/// \brief specialization of the standard std::hash function.
26template<>
27struct hash<atermpp::detail::_aterm*>
28{
29 std::size_t operator()(const atermpp::detail::_aterm* term) const
30 {
31 // The hash function given here shifts a term four positions to the right.
32 // This is very effective in the toolset, as the aterms are often stored
33 // in consecutive positions and this means they are stored in consecutive positions
34 // in hash tables based on chaining. However, this has function is very disadvantageous
35 // for other hash tables, especially those with open addressing. In that case
36 // it is much better to use the hash function below, which unfortunately can lead
37 // to a performance drop of 1/3, compared to the ">> 4" hash below.
38 // The reason for the performance drop is most likely that with better hashing
39 // the items are better dispersed in hash tables, leading to worse cache behaviour.
40 // std::hash<const void*> hasher;
41 // return hasher(reinterpret_cast<const void*>(term));
42
43 return reinterpret_cast<std::uintptr_t>(term) >> 4;
44
45 }
46};
47
48/// \brief specialization of the standard std::hash function.
49template<>
51{
52 std::size_t operator()(const atermpp::unprotected_aterm_core& term) const
53 {
54 const std::hash<atermpp::detail::_aterm*> hasher;
55 return hasher(atermpp::detail::address(term));
56 }
57};
58
59/// \brief specialization of the standard std::hash function.
60template<>
61struct hash<atermpp::aterm_core>
62{
63 std::size_t operator()(const atermpp::aterm_core& t) const
64 {
65 const std::hash<atermpp::detail::_aterm*> aterm_hasher;
66 return aterm_hasher(atermpp::detail::address(t));
67 }
68};
69
70} // namespace std
71
72namespace atermpp
73{
74namespace detail
75{
76
77/// \brief Indicates that the number of arguments is not known at compile time.
78constexpr std::size_t DynamicNumberOfArguments = std::numeric_limits<std::size_t>::max();
79
80/// \brief Computes the hash of the given term.
81/// \details Can be optimized with loop unrolling when template parameter N is provided.
82/// However, this assumes that every passed to term has arity equal to N.
83template<std::size_t N = DynamicNumberOfArguments>
85{
86 using is_transparent = void;
87
88 std::size_t operator()(const _aterm& term) const noexcept;
89 std::size_t operator()(const function_symbol& symbol) const noexcept;
90 std::size_t operator()(const function_symbol& symbol, unprotected_aterm_core arguments[]) const noexcept;
91
92 template<typename ForwardIterator,
93 typename std::enable_if<mcrl2::utilities::is_iterator<ForwardIterator>::value, void>::type* = nullptr>
94 std::size_t operator()(const function_symbol& symbol, ForwardIterator begin, ForwardIterator end) const noexcept;
95};
96
97/// \brief Computes the hash of the given term.
98/// \details This version only works whenever N is a compile time constant.
99template<std::size_t N = 0>
101{
102 using is_transparent = void;
103
104 using aterm_hasher<N>::operator();
105 std::size_t operator()(const function_symbol& symbol, std::array<unprotected_aterm_core, N> key) const noexcept;
106
107 template<typename ...Args>
108 std::size_t operator()(const function_symbol& symbol, const Args&... args) const noexcept;
109};
110
111/// \brief Computes the hash of the integral term arguments.
113{
114 using is_transparent = void;
115
116 inline std::size_t operator()(const _aterm_int& term) const noexcept;
117 inline std::size_t operator()(std::size_t value) const noexcept;
118};
119
120/// \brief Returns true iff first and second are value-equivalent.
121/// \details Can be optimized with loop unrolling when template parameter N is provided.
122/// However, this assumes that every passed to term has arity equal to N.
123template<std::size_t N = DynamicNumberOfArguments>
125{
126 using is_transparent = void;
127
128 bool operator()(const _aterm& first, const _aterm& second) const noexcept;
129 bool operator()(const _aterm& term, const function_symbol& symbol) const noexcept;
130 bool operator()(const _aterm& term, const function_symbol& symbol, unprotected_aterm_core arguments[]) const noexcept;
131
132 template<typename ForwardIterator,
133 typename std::enable_if<mcrl2::utilities::is_iterator<ForwardIterator>::value>::type* = nullptr>
134 bool operator()(const _aterm& term, const function_symbol& symbol, ForwardIterator begin, ForwardIterator end) const noexcept;
135};
136
137template<std::size_t N>
139{
140 using aterm_equals<N>::operator();
141 bool operator()(const _aterm& term, const function_symbol& symbol, std::array<unprotected_aterm_core, N> key) const noexcept;
142
143 template<typename ...Args>
144 bool operator()(const _aterm& term, const function_symbol& symbol, const Args&... args) const noexcept;
145};
146
147/// \brief Returns true iff the given term(s) or value are equivalent.
149{
150 using is_transparent = void;
151
152 inline bool operator()(const _aterm_int& first, const _aterm_int& second) const noexcept;
153 inline bool operator()(const _aterm_int& term, std::size_t value) const noexcept;
154};
155
156/// \brief Auxiliary function to combine hnr with aterms.
157inline
158std::size_t combine(const std::size_t hnr, const unprotected_aterm_core& term)
159{
160 const std::hash<unprotected_aterm_core> hasher;
161 return mcrl2::utilities::detail::hash_combine_cheap(hnr, hasher(term));
162}
163
164/// Implementation
165
166template<std::size_t N>
167std::size_t aterm_hasher<N>::operator()(const _aterm& term) const noexcept
168{
169 const function_symbol& f = term.function();
170 std::size_t hnr = operator()(f);
171
172 // The arity is defined by the function symbol iff N is unchanged and the arity is N otherwise.
173 const std::size_t arity = (N == DynamicNumberOfArguments) ? f.arity() : N;
174
175 // This is a function application with arguments, hash each argument and combine the result.
176 const _aterm_appl<>& term_appl = static_cast<const _aterm_appl<>&>(term);
177 for (std::size_t i = 0; i < arity; ++i)
178 {
179 hnr = combine(hnr, term_appl.arg(i));
180 }
181
182 return hnr;
183}
184template<std::size_t N>
185std::size_t aterm_hasher<N>::operator()(const function_symbol& symbol) const noexcept
186{
187 const std::hash<function_symbol> function_hasher;
188 return function_hasher(symbol);
189}
190
191template<std::size_t N>
192std::size_t aterm_hasher<N>::operator()(const function_symbol& symbol, unprotected_aterm_core arguments[]) const noexcept
193{
194 // The arity is defined by the function symbol iff N is unchanged and the arity is N otherwise.
195 const std::size_t arity = (N == DynamicNumberOfArguments) ? symbol.arity() : N;
196
197 // This is a function application with arguments, hash each argument and combine the result.
198 std::size_t hnr = operator()(symbol);
199 for (std::size_t i = 0; i < arity; ++i)
200 {
201 hnr = combine(hnr, arguments[i]);
202 }
203
204 return hnr;
205}
206
207template<std::size_t N>
208template<typename ForwardIterator,
210inline std::size_t aterm_hasher<N>::operator()(const function_symbol& symbol, ForwardIterator it, ForwardIterator end) const noexcept
211{
212 // The end is only used for debugging to ensure that the arity and std::distance(it, end) match.
213 mcrl2::utilities::mcrl2_unused(end);
214
215 // The arity is defined by the function symbol iff N is unchanged and the arity is N otherwise.
216 const std::size_t arity = (N == DynamicNumberOfArguments) ? symbol.arity() : N;
217
218 // This is a function application with arguments, hash each argument and combine the result.
219 std::size_t hnr = operator()(symbol);
220 for (std::size_t i = 0; i < arity; ++i)
221 {
222 assert(it != end);
223 hnr = combine(hnr, *it);
224 ++it;
225 }
226
227 assert(it == end);
228 return hnr;
229}
230
231template<std::size_t N>
232std::size_t aterm_hasher_finite<N>::operator()(const function_symbol& symbol, std::array<unprotected_aterm_core, N> arguments) const noexcept
233{
234 std::size_t hnr = operator()(symbol);
235
236 // This is a function application with arguments, hash each argument and combine the result.
237 for (std::size_t i = 0; i < N; ++i)
238 {
239 hnr = combine(hnr, arguments[i]);
240 }
241
242 return hnr;
243}
244
245template<std::size_t I = 0, typename... Tp,
246 typename std::enable_if<I == sizeof...(Tp), void>::type* = nullptr>
247std::size_t combine_args(std::size_t seed, const Tp&...)
248{
249 return seed;
250}
251
252template<std::size_t I = 0, typename... Tp,
253 typename std::enable_if<I < sizeof...(Tp), void>::type* = nullptr>
254std::size_t combine_args(std::size_t seed, const Tp&... t)
255{
256 return combine_args<I+1>(combine(seed, std::get<I>(std::forward_as_tuple(t...))), t...);
257}
258
259template<std::size_t N>
260template<typename ...Args>
261std::size_t aterm_hasher_finite<N>::operator()(const function_symbol& symbol, const Args&... args) const noexcept
262{
263 std::size_t hnr = operator()(symbol);
264
265 // This is a function application with arguments, hash each argument and combine the result.
266 return combine_args(hnr, args...);
267}
268
269std::size_t aterm_int_hasher::operator()(const _aterm_int& term) const noexcept
270{
271 return aterm_int_hasher()(term.value());
272}
273
274// The size_t hashfunction below has been taken from a note on stackoverflow
275// by Wolfgang Brehm.
276static inline std::size_t xorshift(const std::size_t n, const std::size_t i)
277{
278 return n^(n>>i);
279}
280
281std::size_t aterm_int_hasher::operator()(std::size_t value) const noexcept
282{
283 const std::size_t p = 0x5555555555555555ull; // pattern of alternating 0 and 1
284 const std::size_t c = 17316035218449499591ull;// random odd integer constant;
285 return c*xorshift(p*xorshift(value,32),32);
286}
287
288template<std::size_t N>
289bool aterm_equals<N>::operator()(const _aterm& first, const _aterm& second) const noexcept
290{
291 if (&first == &second)
292 {
293 // If the pointers are equal they match by definition
294 return true;
295 }
296
297 // The arity is defined by the function symbol iff N is unchanged and the arity is N otherwise.
298 const std::size_t arity = (N == DynamicNumberOfArguments) ? first.function().arity() : N;
299
300 // Check whether the remaining arguments match
301 for (std::size_t i = 0; i < arity; ++i)
302 {
303 if (static_cast<const _term_appl&>(first).arg(i)
304 != static_cast<const _term_appl&>(second).arg(i))
305 {
306 return false;
307 }
308 }
309
310 return first.function() == second.function();
311}
312
313template<std::size_t N>
314bool aterm_equals<N>::operator()(const _aterm& term, const function_symbol& symbol) const noexcept
315{
316 return term.function() == symbol;
317}
318
319template<std::size_t N>
320bool aterm_equals<N>::operator()(const _aterm& term, const function_symbol& symbol, unprotected_aterm_core arguments[]) const noexcept
321{
322 // Each argument should be equal.
323 for (std::size_t i = 0; i < symbol.arity(); ++i)
324 {
325 if (static_cast<const _term_appl&>(term).arg(i) != arguments[i])
326 {
327 return false;
328 }
329 }
330
331 return term.function() == symbol;
332}
333
334template<std::size_t N>
335template<typename ForwardIterator,
337inline bool aterm_equals<N>::operator()(const _aterm& term, const function_symbol& symbol, ForwardIterator it, ForwardIterator end) const noexcept
338{
339 // The end is only used for debugging to ensure that the arity and std::distance(it, end) match.
340 mcrl2::utilities::mcrl2_unused(end);
341
342 const std::size_t arity = (N == DynamicNumberOfArguments) ? symbol.arity() : N;
343
344 // Each argument should be equal.
345 for (std::size_t i = 0; i < arity; ++i)
346 {
347 assert(it != end);
348 if (static_cast<const _term_appl&>(term).arg(i) != (*it))
349 {
350 return false;
351 }
352 ++it;
353 }
354
355 assert(it == end);
356 return term.function() == symbol;
357}
358
359template<std::size_t N>
360bool aterm_equals_finite<N>::operator()(const _aterm& term, const function_symbol& symbol, std::array<unprotected_aterm_core, N> arguments) const noexcept
361{
362 // Each argument should be equal.
363 for (std::size_t i = 0; i < N; ++i)
364 {
365 if (static_cast<const _aterm_appl<N>&>(term).arg(i) != arguments[i])
366 {
367 return false;
368 }
369 }
370
371 return term.function() == symbol;
372}
373
374template<std::size_t I = 0,
375 typename... Tp,
376 typename std::enable_if<I == sizeof...(Tp), void>::type* = nullptr>
377bool equal_args(const _aterm_appl<8>&, const Tp&...)
378{
379 return true;
380}
381
382template<std::size_t I = 0,
383 typename... Tp,
384 typename std::enable_if<I < sizeof...(Tp), void>::type* = nullptr>
385bool equal_args(const _aterm_appl<8>& term, const Tp&... t)
386{
387 return term.arg(I) == std::get<I>(std::forward_as_tuple(t...)) && equal_args<I+1>(term, t...);
388}
389
390template<std::size_t N>
391template<typename ...Args>
392bool aterm_equals_finite<N>::operator()(const _aterm& term, const function_symbol& symbol, const Args&... args) const noexcept
393{
394 return term.function() == symbol && equal_args(static_cast<const _aterm_appl<8>&>(term), args...);
395}
396
397bool aterm_int_equals::operator()(const _aterm_int& first, const _aterm_int& second) const noexcept
398{
399 return (first.value() == second.value());
400}
401
402bool aterm_int_equals::operator()(const _aterm_int& term, std::size_t value) const noexcept
403{
404 return (term.value() == value);
405}
406
407} // namespace detail
408} // namespace atermpp
409
410#endif // MCRL2_ATERMPP_DETAIL_ATERM_HASH_H_
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,...,...
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,...,...
void benchmark_threads(std::size_t number_of_threads, F f)
The aterm_core base class that provides protection of the underlying shared terms.
Definition aterm_core.h:182
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(const function_symbol &sym, InputIterator begin, InputIterator end, TermConverter converter)
Definition aterm.h:116
const_iterator end() const
Returns a const_iterator pointing past the last argument.
Definition aterm.h:172
aterm(const function_symbol &symbol, const Terms &...arguments)
Constructor for n-arity function application.
Definition aterm.h:137
const aterm & operator[](const size_type i) const
Returns the i-th argument.
Definition aterm.h:187
aterm()
Default constructor.
Definition aterm.h:48
const_iterator begin() const
Returns an iterator pointing to the first argument.
Definition aterm.h:165
aterm(const function_symbol &sym, InputIterator begin, InputIterator end)
Constructor that provides an aterm based on a function symbol and an input iterator providing the arg...
Definition aterm.h:96
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:75
aterm & operator=(const aterm &other) noexcept=default
const function_symbol & function() const
Returns the function symbol belonging to an aterm.
Definition aterm.h:144
std::size_t size_type
An unsigned integral type.
Definition aterm.h:36
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:30
ptrdiff_t difference_type
A signed integral type.
Definition aterm.h:39
bool empty() const
Returns true if the term has no arguments.
Definition aterm.h:158
aterm & operator=(aterm &&other) noexcept=default
aterm(const function_symbol &sym)
Constructor.
Definition aterm.h:128
term_appl_iterator< aterm > iterator
Iterator used to iterate through an term_appl.
Definition aterm.h:42
size_type size() const
Returns the number of arguments of this term.
Definition aterm.h:151
term_appl_iterator< aterm > const_iterator
Const iterator used to iterate through an term_appl.
Definition aterm.h:45
constexpr size_type max_size() const
Returns the largest possible number of arguments.
Definition aterm.h:179
This class allocates _aterm_appl objects where the size is based on the arity of the function symbol.
Definition aterm.h:120
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:150
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:141
std::allocator< char > m_packed_allocator
Definition aterm.h:189
static constexpr std::size_t term_appl_size(std::size_t arity)
Definition aterm.h:123
void destroy(T *element)
Specialize destroy for _aterm_appl to only destroy the function symbol. The reference count for the a...
Definition aterm.h:165
constexpr std::size_t capacity() const
Definition aterm.h:184
void deallocate(T *element, std::size_t)
Definition aterm.h:174
constexpr bool has_free_slots() const noexcept
Definition aterm.h:186
constexpr std::size_t consolidate() const noexcept
Definition aterm.h:185
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:159
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 &sym, const Terms &...arguments)
Constructs a term application with the given symbol and arguments.
Definition aterm.h:41
_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:79
_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:69
std::array< unprotected_aterm_core, N > m_arguments
Definition aterm.h:109
operator _aterm_appl< 1 > &()
Convert any known number of arguments aterm<N> to the default _aterm_appl.
Definition aterm.h:103
_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:52
const aterm_core & arg(std::size_t index) const
Definition aterm.h:97
The underlying integer term that actually carries the integer data.
Definition aterm_int.h:22
std::size_t value() const noexcept
Definition aterm_int.h:30
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
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...
std::stack< std::reference_wrapper< _aterm > > todo
A reusable todo stack.
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. \threadsafe.
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 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.
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:82
const function_symbol & as_int() noexcept
Definition aterm_pool.h:118
void created_term(bool allow_collect, mcrl2::utilities::shared_mutex &mutex)
Triggers garbage collection and resizing when conditions are met.
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:216
std::atomic< long > m_count_until_resize
Definition aterm_pool.h:214
function_symbol create_function_symbol(std::string &&name, const std::size_t arity, const 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:189
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:192
void collect_impl(mcrl2::utilities::shared_mutex &mutex)
Collect garbage on all storages.
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:210
const function_symbol & as_empty_list() noexcept
Definition aterm_pool.h:124
function_symbol create_function_symbol(const std::string &name, const std::size_t arity, const bool check_for_registered_functions=false)
Creates a function symbol pair (name, arity).
const function_symbol & as_list() noexcept
Definition aterm_pool.h:121
aterm_core m_empty_list
Represents an empty list.
Definition aterm_pool.h:222
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:213
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:115
mcrl2::utilities::shared_mutex m_shared_mutex
Garbage collection is enabled.
Definition aterm_pool.h:219
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:132
integer_term_storage m_int_storage
Storage for integral terms.
Definition aterm_pool.h:195
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:130
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 mark()
Mark the terms created by this thread to prevent them being garbage collected.
Definition aterm_pool.h:46
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:226
void print_local_performance_statistics() const
Print performance statistics for data stored for this thread.
Definition aterm_pool.h:52
std::function< std::size_t()> m_protection_set_size_function
Definition aterm_pool.h:70
void create_term(aterm &term, const function_symbol &sym)
Generates unique function symbols with a given prefix.
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.
void swap(function_symbol &f)
Swap this function with its argument.
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.
term_appl_iterator operator++(int)
Postfix increment.
bool operator==(const term_appl_iterator &other) const
Equality of iterators.
bool operator<(const term_appl_iterator &other) const
Comparison of iterators.
term_appl_iterator(const term_appl_iterator &other)
The copy constructor.
bool operator>=(const term_appl_iterator &other) const
Comparison of iterators.
term_appl_iterator operator-(ptrdiff_t n) const
Decrease by a constant value.
term_appl_iterator & operator=(const term_appl_iterator &other)
The assignment operator.
term_appl_iterator & operator--()
Prefix decrement.
ptrdiff_t operator-(const term_appl_iterator &other) const
The negative distance from this to the other iterator.
std::random_access_iterator_tag iterator_category
bool operator<=(const term_appl_iterator &other) const
Comparison of iterators.
friend term_appl_iterator< Derived > detail::aterm_appl_iterator_cast(term_appl_iterator< Base > a, typename std::enable_if< std::is_base_of< aterm, Base >::value &&std::is_base_of< aterm, Derived >::value >::type *)
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.
bool operator!=(const term_appl_iterator &other) const
Inequality of iterators.
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.
bool operator>(const term_appl_iterator &other) const
Comparison of iterators.
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 list of aterm objects.
Definition aterm_list.h:24
An unprotected term does not change the reference count of the shared term when it is copied or moved...
Definition aterm_core.h:32
bool operator<=(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
Definition aterm_core.h:122
bool operator>=(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
Definition aterm_core.h:131
bool type_is_list() const noexcept
Dynamic check whether the term is an aterm_list.
Definition aterm_core.h:72
void swap(unprotected_aterm_core &t) noexcept
Swaps this term with its argument.
Definition aterm_core.h:152
bool operator>(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
Definition aterm_core.h:113
bool operator<(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
Definition aterm_core.h:104
bool operator==(const unprotected_aterm_core &t) const
Comparison operator.
Definition aterm_core.h:83
unprotected_aterm_core() noexcept
Default constuctor.
Definition aterm_core.h:41
bool type_is_appl() const noexcept
Dynamic check whether the term is an aterm.
Definition aterm_core.h:55
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:143
friend detail::_aterm * detail::address(const unprotected_aterm_core &t)
const detail::_aterm * m_term
Definition aterm_core.h:36
bool operator!=(const unprotected_aterm_core &t) const
Inequality operator on two unprotected aterms.
Definition aterm_core.h:92
const function_symbol & function() const
Yields the function symbol in an aterm.
Definition aterm_core.h:161
bool type_is_int() const noexcept
Dynamic check whether the term is an aterm_int.
Definition aterm_core.h:63
unprotected_aterm_core(const detail::_aterm *term) noexcept
Constructor.
Definition aterm_core.h:47
A helper class to keep track of the number of hits and misses for cache-like data structures.
Inherit from this class to prevent it from being copyable.
Definition noncopyable.h:21
noncopyable & operator=(const noncopyable &)=delete
noncopyable(const noncopyable &)=delete
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
bool operator>=(const shared_reference &other) const noexcept
shared_reference< T > & operator=(shared_reference< T > &&other) noexcept
Move assignment constructor.
bool defined() const
Check whether the shared_reference has a valid reference.
bool operator>(const shared_reference< T > &other) const noexcept
shared_reference() noexcept
The default constructor.
void swap(shared_reference< T > &other)
Swaps *this with the other shared reference.
utilities::tagged_pointer< T > m_reference
shared_reference< T > & operator=(const shared_reference< T > &other) noexcept
Copy assignment constructor.
bool operator!=(const shared_reference< T > &other) const noexcept
bool operator<=(const shared_reference< T > &other) const noexcept
shared_reference(shared_reference< T > &&other) noexcept
Move constructor.
shared_reference(const shared_reference< T > &other) noexcept
Copy constructor.
bool operator<(const shared_reference< T > &other) const noexcept
shared_reference(T *reference) noexcept
Takes ownership of the passed reference, which means that its reference count is incremented.
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>(const tagged_pointer &other) const noexcept
bool operator>=(const tagged_pointer &other) const noexcept
bool operator==(std::nullptr_t) const
void swap(tagged_pointer< T > &other)
void untag() const
Remove the tag.
bool operator<(const tagged_pointer &other) const noexcept
void tag() const
Apply a tag to the pointer that can be checked with tagged().
bool operator!=(std::nullptr_t) const
bool operator<=(const tagged_pointer &other) const noexcept
bool operator!=(const tagged_pointer &other) const
std::conditional_t< detail::GlobalThreadSafe, detail::atomic_wrapper< T * >, T * > m_pointer
Implements a simple stopwatch that starts on construction.
Definition stopwatch.h:17
double seconds()
Definition stopwatch.h:37
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.
std::aligned_storage< sizeof(aterm_pool), alignof(aterm_pool)>::type g_aterm_pool_storage
Storage for a global term pool that is not initialized.
aterm 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...
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
static aterm_pool & g_aterm_pool_instance
A reference to the global term pool storage.
aterm 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.
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:158
std::size_t combine_args(std::size_t seed, const Tp &...)
Definition aterm_hash.h:247
aterm 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_list
static constexpr bool EnableGarbageCollectionMetrics
Enable to print garbage collection statistics.
term_appl_iterator< Derived > aterm_appl_iterator_cast(term_appl_iterator< Base > a, typename std::enable_if< std::is_base_of< aterm, Base >::value &&std::is_base_of< aterm, Derived >::value >::type *=nullptr)
This function can be used to translate an term_appl_iterator of one sort into another.
static constexpr bool EnableAggressiveGarbageCollection
Performs garbage collection intensively for testing purposes.
function_symbol g_as_int
These function symbols are used to indicate integer, list and empty list terms.
static constexpr bool EnableBlockAllocator
Enable the block allocator for terms.
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 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.
void debug_print(std::ostream &o, const _aterm *t, const std::size_t d=3)
aterm 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...
void mark_term(const _aterm &root, std::stack< std::reference_wrapper< _aterm > > &todo)
Marks a term and recursively all arguments that are not reachable.
constexpr std::size_t DynamicNumberOfArguments
Indicates that the number of arguments is not known at compile time.
Definition aterm_hash.h:78
The main namespace for the aterm++ library.
Definition algorithm.h:21
void make_term_appl(Term &target, const function_symbol &sym, InputIterator begin, InputIterator end, TermConverter converter)
Constructor an aterm in a variable based on a function symbol and an forward iterator providing the a...
Definition aterm.h:268
term_list< aterm > aterm_list
A term_list with elements of type aterm.
Definition aterm_list.h:497
void make_term_appl(Term &target, const function_symbol &sym)
Make an term_appl consisting of a single function symbol.
Definition aterm.h:286
Derived & reference_cast(Derived &t)
A cast from one aterm based type to another, as a reference, allowing to assign to it.
Definition aterm.h:370
void(* term_callback)(const aterm &)
Definition aterm.h:194
std::string pp(const atermpp::aterm &t)
Transform an aterm to an ascii string.
Definition aterm.h:440
void make_term_appl(Term &target, const function_symbol &symbol, const Terms &...arguments)
Make an aterm application for n-arity function application.
Definition aterm.h:301
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:213
void make_term_appl(Term &target, const function_symbol &sym, InputIterator begin, InputIterator end)
Constructor an aterm in a variable based on a function symbol and an input iterator providing the arg...
Definition aterm.h:241
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...
const DerivedCont & container_cast(const Cont< Base > &t, typename std::enable_if_t< is_container< DerivedCont, aterm >::value &&std::is_same_v< Cont< typename DerivedCont::value_type >, DerivedCont > &&!std::is_base_of_v< DerivedCont, Cont< Base > > &&is_convertible< Base, typename DerivedCont::value_type >::value > *=nullptr)
Definition aterm.h:379
void make_term_appl_with_index(aterm &target, const function_symbol &symbol, const Terms &...arguments)
Constructor for n-arity function application with an index.
Definition aterm.h:313
const Derived & vertical_cast(const Base &t, typename std::enable_if< is_convertible< Base, Derived >::value >::type *=nullptr)
A cast form an aterm derived class to a class that inherits in possibly multiple steps from this clas...
Definition aterm.h:399
const Derived & down_cast(const Base &t, typename std::enable_if< is_convertible< Base, Derived >::value &&!std::is_base_of< Derived, Base >::value >::type *=nullptr)
A cheap cast from one aterm based type to another When casting one aterm based type into another,...
Definition aterm.h:337
const DerivedCont & vertical_cast(const Cont< Base > &t, typename std::enable_if_t< is_container< DerivedCont, aterm >::value &&std::is_same_v< Cont< typename DerivedCont::value_type >, DerivedCont > &&is_convertible< Base, typename DerivedCont::value_type >::value > *=nullptr)
Definition aterm.h:409
Derived & reference_cast(Base &t, typename std::enable_if< is_convertible< Base, Derived >::value &&!std::is_base_of< Derived, Base >::value >::type *=nullptr)
A cast from one aterm based type to another, as a reference, allowing to assign to it.
Definition aterm.h:352
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
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.
T * tag(const T *p)
Applies a tag to a pointer.
bool tagged(const T *p)
T * pointer(const detail::atomic_wrapper< T * > &p)
T * pointer(const T *p)
T * tag(const detail::atomic_wrapper< T * > &p)
constexpr bool is_iterable_v
Definition type_traits.h:50
static constexpr bool EnableReferenceCountMetrics
Enable to count the number of reference count changes.
bool tagged(const detail::atomic_wrapper< T * > &p)
constexpr bool is_iterator_v
Definition type_traits.h:53
void mcrl2_unused(T &&...)
Function that can be used to silence unused parameter warnings.
Definition unused.h:20
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
void swap(atermpp::aterm &t1, atermpp::aterm &t2) noexcept
Swaps two term_applss.
Definition aterm.h:475
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:462
int main(int argc, char *argv[])
_aterm_appl_allocator< U > other
Definition aterm.h:136
bool operator()(const _aterm &term, const function_symbol &symbol, const Args &... args) const noexcept
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:125
bool operator()(const _aterm &term, const function_symbol &symbol, ForwardIterator begin, ForwardIterator end) const noexcept
bool operator()(const _aterm &first, const _aterm &second) const noexcept
bool operator()(const _aterm &term, const function_symbol &symbol) const noexcept
bool operator()(const _aterm &term, const function_symbol &symbol, unprotected_aterm_core arguments[]) const noexcept
Computes the hash of the given term.
Definition aterm_hash.h:101
std::size_t operator()(const function_symbol &symbol, const Args &... args) const noexcept
std::size_t operator()(const function_symbol &symbol, std::array< unprotected_aterm_core, N > key) const noexcept
Definition aterm_hash.h:232
Computes the hash of the given term.
Definition aterm_hash.h:85
std::size_t operator()(const function_symbol &symbol) const noexcept
Definition aterm_hash.h:185
std::size_t operator()(const _aterm &term) const noexcept
Implementation.
Definition aterm_hash.h:167
std::size_t operator()(const function_symbol &symbol, ForwardIterator begin, ForwardIterator end) const noexcept
Definition aterm_hash.h:210
std::size_t operator()(const function_symbol &symbol, unprotected_aterm_core arguments[]) const noexcept
Definition aterm_hash.h:192
Returns true iff the given term(s) or value are equivalent.
Definition aterm_hash.h:149
bool operator()(const _aterm_int &term, std::size_t value) const noexcept
bool operator()(const _aterm_int &first, const _aterm_int &second) const noexcept
Computes the hash of the integral term arguments.
Definition aterm_hash.h:113
std::size_t operator()(const _aterm_int &term) const noexcept
std::size_t operator()(std::size_t value) const noexcept
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
atomic_wrapper & operator=(const atomic_wrapper< T > &other)
atomic_wrapper(const atomic_wrapper< T > &other)
Checks whether condition holds for all types passed as variadic template.
Definition type_traits.h:41
A typetrait that is std::true_type iff std::begin() and std::end() can be called on type T.
Definition type_traits.h:21
A typetrait that is std::true_type iff the given type has the iterator traits.
Definition type_traits.h:31
std::size_t operator()(const atermpp::aterm &t) const
Definition aterm.h:483
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::reference_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