mCRL2
Loading...
Searching...
No Matches
hashtable.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#ifndef MCRL2_UTILITIES_HASHTABLE_H
10#define MCRL2_UTILITIES_HASHTABLE_H
11
12#include <vector>
13
15
16namespace mcrl2
17{
18namespace utilities
19{
20
22template<typename Key,
23 typename Hash = std::hash<Key>,
24 typename Equals = std::equal_to<Key>,
25 typename Allocator = std::allocator<Key>>
27{
28public:
29 typedef Key key_type;
30 typedef std::size_t size_type;
31 typedef std::pair<const key_type, size_type> value_type;
32 typedef Equals key_equal;
33 typedef Hash hasher;
34
38 typedef const value_type* const_pointer;
39
40 typedef typename std::vector < Key >::iterator iterator;
41 typedef typename std::vector < Key >::const_iterator const_iterator;
42
43 typedef typename std::vector < Key >::reverse_iterator reverse_iterator;
44 typedef typename std::vector < Key >::const_reverse_iterator const_reverse_iterator;
45
46 typedef std::ptrdiff_t difference_type;
47
49 hashtable();
50
55 hashtable(std::size_t initial_hashtable_size,
56 const hasher& hash = hasher(),
57 const key_equal& equals = key_equal());
58
62 {
63 return m_hashtable.begin();
64 }
65
68 {
69 return m_hashtable.end();
70 }
71
75 {
76 return m_hashtable.begin();
77 }
78
80 iterator end() const
81 {
82 return m_hashtable.end();
83 }
84
87 {
88 return m_hashtable.cbegin();
89 }
90
93 {
94 return m_hashtable.cend();
95 }
96
99 {
100 return m_hashtable.rbegin();
101 }
102
105 {
106 return m_hashtable.rend();
107 }
108
111 {
112 return m_hashtable.crbegin();
113 }
114
117 {
118 return m_hashtable.crend();
119 }
120
122 void clear();
123
129 std::pair<iterator, bool> insert(const key_type& key);
130
133 iterator erase(const key_type& key);
134
136 iterator find(const key_type& key);
137
141 {
143 }
144
146 bool must_resize();
147
149 void resize();
150
151
152private:
154 std::size_t get_index(const key_type& key);
155
156 std::vector<Key> m_hashtable;
157
159 Equals m_equals;
160
161 std::size_t m_number_of_elements = 0;
162
165
167 inline void rehash(std::size_t size);
168};
169
170} // end namespace utilities
171} // end namespace mcrl2
172
174
175
176#endif // MCRL2_UTILITIES_HASHTABLE_H
A set that assigns each element an unique index.
Definition hashtable.h:27
iterator end()
End of the forward iterator.
Definition hashtable.h:67
size_type size() const
The number of elements in the indexed set.
Definition hashtable.h:140
iterator end() const
End of the forward iterator.
Definition hashtable.h:80
void clear()
Clears the indexed set by removing all its elements. It is not guaranteed that the memory is released...
Definition hashtable.h:72
const_iterator crend() const
End of the reverse const_iterator.
Definition hashtable.h:116
iterator find(const key_type &key)
Find the given key and returns an iterator to that position.
Definition hashtable.h:150
iterator rbegin()
Reverse iterator going through the elements in the set from the largest to the smallest index.
Definition hashtable.h:98
std::vector< Key >::iterator iterator
Definition hashtable.h:40
std::pair< const key_type, size_type > value_type
Definition hashtable.h:31
std::vector< Key >::reverse_iterator reverse_iterator
Definition hashtable.h:43
void rehash(std::size_t size)
Resizes the hash table to the given power of two size.
Definition hashtable.h:24
const value_type * const_pointer
Definition hashtable.h:38
void resize()
Resize the hashtable. This is not done automatically.
Definition hashtable.h:84
std::vector< Key >::const_reverse_iterator const_reverse_iterator
Definition hashtable.h:44
std::size_t get_index(const key_type &key)
Definition hashtable.h:166
hashtable()
Constructor of an empty indexed set. Starts with a hashtable of size 128.
Definition hashtable.h:54
const_iterator cbegin() const
const_iterator going through the elements in the set numbered from zero upwards.
Definition hashtable.h:86
size_type m_buckets_mask
Always equal to m_hashtable.size() - 1.
Definition hashtable.h:164
bool must_resize()
Check whether the hashtable must be resized. This is not automatic and must be done explicitly.
Definition hashtable.h:78
iterator begin()
Forward iterator which runs through the elements from the lowest to the largest number.
Definition hashtable.h:61
std::pair< iterator, bool > insert(const key_type &key)
Insert a key in the indexed set and return its index.
Definition hashtable.h:90
const_iterator crbegin() const
Reverse const_iterator going through the elements from the highest to the lowest numbered element.
Definition hashtable.h:110
std::vector< Key > m_hashtable
Definition hashtable.h:156
const value_type & const_reference
Definition hashtable.h:36
std::size_t m_number_of_elements
Definition hashtable.h:161
iterator rend()
End of the reverse iterator.
Definition hashtable.h:104
iterator begin() const
Forward iterator which runs through the elements from the lowest to the largest number.
Definition hashtable.h:74
const_iterator cend() const
End of the forward const_iterator.
Definition hashtable.h:92
std::vector< Key >::const_iterator const_iterator
Definition hashtable.h:41
std::ptrdiff_t difference_type
Definition hashtable.h:46
iterator erase(const key_type &key)
Erases the key assuming that this key is present in the hashtable..
Definition hashtable.h:118
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
#define hash(l, r, m)
Definition tree_set.cpp:23