mCRL2
Loading...
Searching...
No Matches
function_symbol_pool.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 DETAIL_FUNCTION_SYMBOL_POOL_H
11#define DETAIL_FUNCTION_SYMBOL_POOL_H
12
17
18namespace atermpp
19{
20namespace detail
21{
22
25{
26public:
28
35 function_symbol create(const std::string& name, const std::size_t arity, const bool check_for_registered_functions = false);
36 function_symbol create(std::string&& name, const std::size_t arity, const bool check_for_registered_functions = false);
37
40 void deregister(const std::string& prefix);
41
46 std::shared_ptr<std::size_t> register_prefix(const std::string& prefix);
47
49 void resize_if_needed();
50
53 std::size_t get_sufficiently_large_postfix_index(const std::string& prefix) const;
54
56 void sweep();
57
59 const function_symbol& as_int() noexcept { return m_as_int; }
60
62 const function_symbol& as_list() noexcept { return m_as_list; }
63
65 const function_symbol& as_empty_list() noexcept { return m_as_empty_list; }
66
68 std::size_t size() const noexcept { return m_symbol_set.size(); }
69
71 std::size_t capacity() const noexcept { return m_symbol_set.capacity(); }
72
73private:
78 typename std::conditional_t<EnableBlockAllocator,
80 std::allocator<_function_symbol>>,
82 false>;
83
86
90 std::map<std::string, std::shared_ptr<std::size_t>> m_prefix_to_register_function_map;
91
92 mutable mcrl2::utilities::mutex m_mutex; // Mutex for m_prefix_to_register_function_map.
93
94 // Default function symbols.
98
99 // Various performance metrics.
101
102 // Create helper function.
103 void create_helper(const std::string& name);
104};
105
106
107} // namespace detail
108} // namespace atermpp
109
110#endif // DETAIL_FUNCTION_SYMBOL_POOL_H
111
Stores the data for a function symbol (name, arity) pair.
This class stores a set of function symbols.
void sweep()
Collect all garbage function symbols.
std::map< std::string, std::shared_ptr< std::size_t > > m_prefix_to_register_function_map
A map that records a function for each prefix that must be called to set the postfix number to a suff...
void deregister(const std::string &prefix)
Restore the index back to index before registering this prefix. \threadsafe.
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)
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(const std::string &name, const std::size_t arity, const bool check_for_registered_functions=false)
Creates a function symbol pair (name, arity), returns a pointer to an existing element if this pair i...
const function_symbol & as_list() noexcept
The block allocator provides the allocator interface for the memory pool class. As such is can be use...
A helper class to keep track of the number of hits and misses for cache-like data structures.
This is simply an exclusive lock based on the standard library with the ability to perform no locks w...
Definition mutex.h:23
Inherit from this class to prevent it from being copyable.
Definition noncopyable.h:21
size_type size() const noexcept
size_type capacity() const noexcept
static constexpr bool EnableBlockAllocator
Enable the block allocator for terms.
The main namespace for the aterm++ library.
Definition algorithm.h:21
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
True iff the given function symbols are equal to eachother or to the given key.
Computes the hash for given function symbol objects and for the function_symbol_key.