10#ifndef MCRL2_UTILITIES_DETAIL_HASHTABLE_H
11#define MCRL2_UTILITIES_DETAIL_HASHTABLE_H
23template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
27 std::vector<Key> old = std::move(m_hashtable);
29 m_hashtable = std::vector<Key>(size,
nullptr);
30 m_buckets_mask = m_hashtable.size() - 1;
32 for (
const Key& key : old)
34 const std::size_t key_index =
get_index(key);
35 auto it = begin() + key_index;
37 while (*it !=
nullptr)
45 assert(it != begin() + key_index);
53template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
59template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
63 : m_hashtable(
std::max(initial_size, detail::minimal_hashtable_size), nullptr),
71template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
77template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
80 return (2 * m_number_of_elements >= m_hashtable.size());
83template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
86 rehash(2 * m_hashtable.size());
89template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
93 assert(!must_resize());
94 ++m_number_of_elements;
96 const std::size_t key_index =
get_index(key);
97 auto it = begin() + key_index;
100 while (*it !=
nullptr)
108 assert(it != begin() + key_index);
113 return std::make_pair(it,
true);
117template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
120 const std::size_t key_index =
get_index(key);
121 auto it = begin() + key_index;
124 while (!m_equals(*it, key))
132 if (it == begin() + key_index)
140 assert(it != begin() + key_index);
144 --m_number_of_elements;
149template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
152 for (
auto it = begin(); it != end(); ++it)
165template <
class Key,
typename Hash,
typename Equals,
typename Allocator>
168 return m_hasher(key) & m_buckets_mask;
A set that assigns each element an unique index.
void clear()
Clears the indexed set by removing all its elements. It is not guaranteed that the memory is released...
iterator find(const key_type &key)
Find the given key and returns an iterator to that position.
std::vector< Key >::iterator iterator
void rehash(std::size_t size)
Resizes the hash table to the given power of two size.
void resize()
Resize the hashtable. This is not done automatically.
std::size_t get_index(const key_type &key)
hashtable()
Constructor of an empty indexed set. Starts with a hashtable of size 128.
size_type m_buckets_mask
Always equal to m_hashtable.size() - 1.
bool must_resize()
Check whether the hashtable must be resized. This is not automatic and must be done explicitly.
std::pair< iterator, bool > insert(const key_type &key)
Insert a key in the indexed set and return its index.
std::vector< Key > m_hashtable
iterator erase(const key_type &key)
Erases the key assuming that this key is present in the hashtable..
static std::size_t get_index(const function_symbol &func)
static constexpr bool is_power_of_two(T value)
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...