40 std::size_t start_of_index = name.find_last_not_of(
"0123456789") + 1;
42 if (start_of_index < name.
size())
44 std::string potential_number = name.substr(start_of_index);
45 std::string prefix = name.substr(0, start_of_index);
51 std::size_t number = std::stoul(potential_number);
52 *prefix_it->second = std::max(*prefix_it->second, number + 1);
54 catch (std::exception&)
80 if (check_for_registered_functions)
104 if (check_for_registered_functions)
127 auto result = it->second;
134 std::shared_ptr<std::size_t> shared_index = std::make_shared<std::size_t>(index);
144 std::size_t index = 0;
147 const std::string& function_name = f.name();
149 if (function_name.compare(0, prefix.size(), prefix) == 0)
151 std::string potential_number = function_name.substr(prefix.size());
152 std::size_t end_of_number;
155 std::size_t number = std::stoul(potential_number, &end_of_number);
156 if (end_of_number == potential_number.size())
164 catch (std::exception&)
178 std::unique_lock lock(
m_mutex);
180 auto timestamp = std::chrono::system_clock::now();
181 std::size_t old_size =
size();
186 if (it->reference_count() == 0)
196 std::size_t erased_blocks = 0;
200 auto sweep_duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timestamp).count();
203 mCRL2log(
mcrl2::log::info) <<
"function_symbol_pool: Garbage collected " << old_size -
size() <<
" function symbols, " <<
size() <<
" function symbols remaining in "
204 << sweep_duration <<
" ms.\n";
size_type size() const
Returns the number of arguments of this term.
Stores the data for a function symbol (name, arity) pair.
const std::string & name() const noexcept
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...
std::size_t size() const noexcept
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.
function_symbol m_as_empty_list
mcrl2::utilities::mutex m_mutex
unordered_set m_symbol_set
Stores the underlying function symbols.
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...
function_symbol m_as_list
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...
void miss()
Should be called when searching the cache was a miss.
void hit()
Should be called when searching the cache was a hit.
std::string message() const
static std::atomic< std::size_t > & reference_count_changes()
Obtain the number of times that this reference count has changed.
void erase(const Args &... args)
Erases the given key_type(args...) from the unordered set.
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.
const_iterator find(const Args &... args) const
Searches whether an object key_type(args...) occurs in the set.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
static constexpr bool EnableHashtableMetrics
Enable to print hashtable collision, size and number of buckets.
static constexpr bool EnableCreationMetrics
Enable to obtain the percentage of terms found compared to allocated.
function_symbol g_as_empty_list
function_symbol g_as_list
static constexpr bool EnableGarbageCollectionMetrics
Enable to print garbage collection statistics.
function_symbol g_as_int
These function symbols are used to indicate integer, list and empty list terms.
The main namespace for the aterm++ library.
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
static constexpr bool EnableReferenceCountMetrics
Enable to count the number of reference count changes.
void print_performance_statistics(const T &unordered_set)
Prints various information for unordered_set like data structures.
add your file description here.