11template<
class ValueType,
class Hash>
13 : map(map), indexIt(indexIt) {
17template<
class ValueType,
class Hash>
19 return &map == &other.map && *indexIt == *other.indexIt;
22template<
class ValueType,
class Hash>
24 return !(*
this == other);
27template<
class ValueType,
class Hash>
33template<
class ValueType,
class Hash>
39template<
class ValueType,
class Hash>
41 return map.getBucketAndValue(*indexIt);
44template<
class ValueType,
class Hash>
46 : loadFactor(loadFactor), bucketSize(bucketSize), currentSize(1), numberOfElements(0) {
47 STORM_LOG_ASSERT(bucketSize % 64 == 0,
"Bucket size must be a multiple of 64.");
49 while (initialSize > 0) {
57 values = std::vector<ValueType>(1ull << currentSize);
60template<
class ValueType,
class Hash>
62 return occupied.get(bucket);
65template<
class ValueType,
class Hash>
67 return numberOfElements;
70template<
class ValueType,
class Hash>
72 return 1ull << currentSize;
75template<
class ValueType,
class Hash>
78 STORM_LOG_TRACE(
"Increasing size of hash map from " << (1ull << (currentSize - 1)) <<
" to " << (1ull << currentSize) <<
".");
82 std::swap(oldBuckets, buckets);
84 std::swap(oldOccupied, occupied);
85 std::vector<ValueType> oldValues = std::vector<ValueType>(1ull << currentSize);
86 std::swap(oldValues, values);
89 [[maybe_unused]] uint64_t oldSize = numberOfElements;
91 for (
auto bucketIndex : oldOccupied) {
92 findOrAddAndGetBucket(oldBuckets.
get(bucketIndex * bucketSize, bucketSize), oldValues[bucketIndex]);
94 STORM_LOG_ASSERT(oldSize == numberOfElements,
"Size mismatch in rehashing. Size before was " << oldSize <<
" and new size is " << numberOfElements <<
".");
97template<
class ValueType,
class Hash>
99 return findOrAddAndGetBucket(key, value).first;
102template<
class ValueType,
class Hash>
106 std::pair<bool, uint64_t> flagAndBucket = this->findBucket(key);
107 if (flagAndBucket.first) {
108 return std::make_pair(values[flagAndBucket.second], flagAndBucket.second);
111 buckets.set(flagAndBucket.second * bucketSize, key);
112 occupied.set(flagAndBucket.second);
113 values[flagAndBucket.second] = value;
115 return std::make_pair(value, flagAndBucket.second);
119template<
class ValueType,
class Hash>
122 if (numberOfElements >= loadFactor * (1ull << currentSize)) {
123 this->increaseSize();
129template<
class ValueType,
class Hash>
131 std::pair<bool, uint64_t> flagBucketPair = this->findBucket(key);
133 return values[flagBucketPair.second];
136template<
class ValueType,
class Hash>
138 return values[bucket];
141template<
class ValueType,
class Hash>
143 return findBucket(key).first;
146template<
class ValueType,
class Hash>
151template<
class ValueType,
class Hash>
156template<
class ValueType,
class Hash>
161template<
class ValueType,
class Hash>
163 STORM_LOG_ASSERT(key.
size() == bucketSize,
"Size of bit vector and size of buckets do not match");
164 uint64_t bucket = hasher(key) >> this->getCurrentShiftWidth();
166 while (isBucketOccupied(bucket)) {
167 if (buckets.matches(bucket * bucketSize, key)) {
168 return std::make_pair(
true, bucket);
171 if (bucket == (1ull << currentSize)) {
176 return std::make_pair(
false, bucket);
179template<
class ValueType,
class Hash>
181 return std::make_pair(buckets.get(bucket * bucketSize, bucketSize), values[bucket]);
184template<
class ValueType,
class Hash>
186 for (
auto pos : occupied) {
187 values[pos] = remapping(values[pos]);
A class that enables iterating over the indices of the bit vector whose corresponding bits are set to...
bool operator==(BitVectorHashMapIterator const &other)
BitVectorHashMapIterator & operator++()
std::pair< storm::storage::BitVector, ValueType > operator*() const
bool operator!=(BitVectorHashMapIterator const &other)
BitVectorHashMapIterator(BitVectorHashMap const &map, BitVector::const_iterator indexIt)
Creates an iterator that points to the bucket with the given index in the given map.
This class represents a hash-map whose keys are bit vectors.
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.
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.
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.
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)