Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BitVectorHashMap.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <functional>
5
7
8namespace storm {
9namespace storage {
10
16// template<typename ValueType, typename Hash = std::hash<storm::storage::BitVector>>
17// template<typename ValueType, typename Hash = FNV1aBitVectorHash>
18template<typename ValueType, typename Hash = Murmur3BitVectorHash<ValueType>>
20 public:
22 public:
29
30 // Methods to compare two iterators.
31 bool operator==(BitVectorHashMapIterator const& other) const;
32 bool operator!=(BitVectorHashMapIterator const& other) const;
33
34 // Methods to move iterator forward.
37
38 // Method to retrieve the currently pointed-to bit vector and its mapped-to value.
39 std::pair<storm::storage::BitVector, ValueType> operator*() const;
40
41 private:
42 // The map this iterator refers to.
43 BitVectorHashMap const& map;
44
45 // An iterator to the bucket this iterator points to.
47 };
48
50
59 BitVectorHashMap(uint64_t bucketSize, uint64_t initialSize = 1000, double loadFactor = 0.75);
60
65
74 ValueType findOrAdd(storm::storage::BitVector const& key, ValueType const& value);
75
86 std::pair<ValueType, uint64_t> findOrAddAndGetBucket(storm::storage::BitVector const& key, ValueType const& value);
87
94 std::pair<storm::storage::BitVector, ValueType> getBucketAndValue(uint64_t bucket) const;
95
102 ValueType getValue(storm::storage::BitVector const& key) const;
103
109 ValueType getValue(uint64_t bucket) const;
110
117 bool contains(storm::storage::BitVector const& key) const;
118
124 const_iterator begin() const;
125
131 const_iterator end() const;
132
138 uint64_t size() const;
139
145 uint64_t capacity() const;
146
152 void remap(std::function<ValueType(ValueType const&)> const& remapping);
153
154 private:
161 bool isBucketOccupied(uint_fast64_t bucket) const;
162
170 std::pair<bool, uint64_t> findBucket(storm::storage::BitVector const& key) const;
171
175 void increaseSize();
176
182 bool checkIncreaseSize();
183
187 uint64_t getCurrentShiftWidth() const;
188
189 // The load factor determining when the size of the map is increased.
190 double loadFactor;
191
192 // The size of one bucket.
193 uint64_t bucketSize;
194
195 // The number of buckets is 2^currentSize.
196 uint64_t currentSize;
197
198 // The buckets that hold the elements of the map.
200
201 // A bit vector that stores which buckets actually hold a value.
203
204 // A vector of the mapped-to values. The entry at position i is the "target" of the key in bucket i.
205 std::vector<ValueType> values;
206
207 // The number of elements in this map.
208 uint64_t numberOfElements;
209
210 // Functor object that are used to perform the actual hashing.
211 Hash hasher;
212};
213
214} // namespace storage
215} // namespace storm
A class that enables iterating over the indices of the bit vector whose corresponding bits are set to...
Definition BitVector.h:23
bool operator==(BitVectorHashMapIterator const &other) const
std::pair< storm::storage::BitVector, ValueType > operator*() const
bool operator!=(BitVectorHashMapIterator const &other) const
BitVectorHashMapIterator(BitVectorHashMap const &map, BitVector::const_iterator indexIt)
Creates an iterator that points to the bucket with the given index in the given map.
BitVectorHashMap(BitVectorHashMap &&)=default
BitVectorHashMap(BitVectorHashMap const &)=default
std::pair< ValueType, uint64_t > findOrAddAndGetBucket(storm::storage::BitVector const &key, ValueType const &value)
Searches for the given key in the map.
ValueType findOrAdd(storm::storage::BitVector const &key, ValueType const &value)
Searches for the given key in the map.
std::pair< storm::storage::BitVector, ValueType > getBucketAndValue(uint64_t bucket) const
Retrieves the key stored in the given bucket (if any) and the value it is mapped to.
BitVectorHashMap(uint64_t bucketSize, uint64_t initialSize=1000, double loadFactor=0.75)
Creates a new hash map with the given bucket size and initial size.
BitVectorHashMap & operator=(BitVectorHashMap &&)=default
ValueType getValue(storm::storage::BitVector const &key) const
Retrieves the value associated with the given key (if any).
const_iterator begin() const
Retrieves an iterator to the elements of the map.
uint64_t capacity() const
Retrieves the capacity of the underlying container.
BitVectorHashMapIterator const_iterator
const_iterator end() const
Retrieves an iterator that points one past the elements of the map.
bool contains(storm::storage::BitVector const &key) const
Checks if the given key is already contained in the map.
void remap(std::function< ValueType(ValueType const &)> const &remapping)
Performs a remapping of all values stored by applying the given remapping.
BitVectorHashMap & operator=(BitVectorHashMap const &)=default
uint64_t size() const
Retrieves the size of the map in terms of the number of key-value pairs it stores.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16