mCRL2
Loading...
Searching...
No Matches
function_symbol_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_FUNCTION_SYMBOL_HASH_H_
11#define MCRL2_ATERMPP_DETAIL_FUNCTION_SYMBOL_HASH_H_
12
14
15#include <cstdint>
16
17namespace std
18{
19
21template<>
22struct hash<atermpp::function_symbol>
23{
24 std::size_t operator()(const atermpp::function_symbol& f) const
25 {
26 // Function symbols take 48 bytes in memory, so when they are packed there
27 // are at least 32 bits that do not distinguish two function symbols. As
28 // such these can be removed.
29 return reinterpret_cast<std::uint64_t>(f.m_function_symbol.get()) >> 5;
30 }
31};
32
34template<>
35struct hash<atermpp::detail::_function_symbol>
36{
38 {
39 std::hash<std::string> string_hasher;
40 std::size_t h = string_hasher(f.name());
41 return (h ^ f.arity());
42 }
43};
44
45} // namespace std
46
47namespace atermpp
48{
49namespace detail
50{
51
55{
56 using is_transparent = void;
57
58 inline std::size_t operator() (const _function_symbol& symbol) const noexcept;
59 inline std::size_t operator() (const std::string& name, std::size_t arity) const noexcept;
60};
61
65{
66 using is_transparent = void;
67
68 inline bool operator() (const _function_symbol& first, const _function_symbol& second) const noexcept;
69 inline bool operator()(const _function_symbol& symbol, const std::string& name, std::size_t arity) const noexcept;
70};
71
72std::size_t function_symbol_hasher::operator() (const _function_symbol& symbol) const noexcept
73{
74 const std::hash<_function_symbol> function_symbol_hasher;
75 return function_symbol_hasher(symbol);
76}
77
78std::size_t function_symbol_hasher::operator() (const std::string& name, std::size_t arity) const noexcept
79{
80 std::hash<std::string> string_hasher;
81 std::size_t h = string_hasher(name);
82 return (h ^ arity);
83}
84
85bool function_symbol_equals::operator() (const _function_symbol& first, const _function_symbol& second) const noexcept
86{
87 return first == second;
88}
89
90bool function_symbol_equals::operator()(const _function_symbol& symbol, const std::string& name, std::size_t arity) const noexcept
91{
92 return (symbol.name() == name) && (symbol.arity() == arity);
93}
94
95} // namespace detail
96} // namespace atermpp
97
98#endif // MCRL2_ATERMPP_DETAIL_FUNCTION_SYMBOL_HASH_H_
Stores the data for a function symbol (name, arity) pair.
const std::string & name() const noexcept
std::size_t arity() const noexcept
detail::_function_symbol::ref m_function_symbol
The shared reference to the underlying function symbol.
The main namespace for the aterm++ library.
Definition algorithm.h:21
STL namespace.
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
std::size_t operator()(const atermpp::detail::_function_symbol &f) const
std::size_t operator()(const atermpp::function_symbol &f) const
#define hash(l, r, m)
Definition tree_set.cpp:23