Browse Source

Set value in BitVectorHashMap

Former-commit-id: 2083df9c4a
tempestpy_adaptions
Mavo 9 years ago
parent
commit
8a77228e32
  1. 24
      src/storage/BitVectorHashMap.cpp
  2. 19
      src/storage/BitVectorHashMap.h

24
src/storage/BitVectorHashMap.cpp

@ -140,6 +140,11 @@ namespace storm {
return findOrAddAndGetBucket(key, value).first; return findOrAddAndGetBucket(key, value).first;
} }
template<class ValueType, class Hash1, class Hash2>
void BitVectorHashMap<ValueType, Hash1, Hash2>::setOrAdd(storm::storage::BitVector const& key, ValueType const& value) {
setOrAddAndGetBucket(key, value);
}
template<class ValueType, class Hash1, class Hash2> template<class ValueType, class Hash1, class Hash2>
std::pair<ValueType, std::size_t> BitVectorHashMap<ValueType, Hash1, Hash2>::findOrAddAndGetBucket(storm::storage::BitVector const& key, ValueType const& value) { std::pair<ValueType, std::size_t> BitVectorHashMap<ValueType, Hash1, Hash2>::findOrAddAndGetBucket(storm::storage::BitVector const& key, ValueType const& value) {
// If the load of the map is too high, we increase the size. // If the load of the map is too high, we increase the size.
@ -161,6 +166,25 @@ namespace storm {
} }
} }
template<class ValueType, class Hash1, class Hash2>
std::size_t BitVectorHashMap<ValueType, Hash1, Hash2>::setOrAddAndGetBucket(storm::storage::BitVector const& key, ValueType const& value) {
// If the load of the map is too high, we increase the size.
if (numberOfElements >= loadFactor * *currentSizeIterator) {
this->increaseSize();
}
std::tuple<bool, std::size_t, bool> flagBucketTuple = this->findBucketToInsert<true>(key);
STORM_LOG_ASSERT(!std::get<2>(flagBucketTuple), "Failed to find bucket for insertion.");
if (!std::get<0>(flagBucketTuple)) {
// Insert the new bits into the bucket.
buckets.set(std::get<1>(flagBucketTuple) * bucketSize, key);
occupied.set(std::get<1>(flagBucketTuple));
++numberOfElements;
}
values[std::get<1>(flagBucketTuple)] = value;
return std::get<1>(flagBucketTuple);
}
template<class ValueType, class Hash1, class Hash2> template<class ValueType, class Hash1, class Hash2>
ValueType BitVectorHashMap<ValueType, Hash1, Hash2>::getValue(storm::storage::BitVector const& key) const { ValueType BitVectorHashMap<ValueType, Hash1, Hash2>::getValue(storm::storage::BitVector const& key) const {
std::pair<bool, std::size_t> flagBucketPair = this->findBucket(key); std::pair<bool, std::size_t> flagBucketPair = this->findBucket(key);

19
src/storage/BitVectorHashMap.h

@ -66,6 +66,15 @@ namespace storm {
* @return The found value if the key is already contained in the map and the provided new value otherwise. * @return The found value if the key is already contained in the map and the provided new value otherwise.
*/ */
ValueType findOrAdd(storm::storage::BitVector const& key, ValueType const& value); ValueType findOrAdd(storm::storage::BitVector const& key, ValueType const& value);
/*!
* Sets the given key value pain in the map. If the key is found in the map, the corresponding value is
* overwritten with the given value. Otherwise, the key is inserted with the given value.
*
* @param key The key to search or insert.
* @param value The value to set.
*/
void setOrAdd(storm::storage::BitVector const& key, ValueType const& value);
/*! /*!
* Searches for the given key in the map. If it is found, the mapped-to value is returned. Otherwise, the * Searches for the given key in the map. If it is found, the mapped-to value is returned. Otherwise, the
@ -79,6 +88,16 @@ namespace storm {
*/ */
std::pair<ValueType, std::size_t> findOrAddAndGetBucket(storm::storage::BitVector const& key, ValueType const& value); std::pair<ValueType, std::size_t> findOrAddAndGetBucket(storm::storage::BitVector const& key, ValueType const& value);
/*!
* Sets the given key value pain in the map. If the key is found in the map, the corresponding value is
* overwritten with the given value. Otherwise, the key is inserted with the given value.
*
* @param key The key to search or insert.
* @param value The value to set.
* @return The index of the bucket into which the key was inserted.
*/
std::size_t setOrAddAndGetBucket(storm::storage::BitVector const& key, ValueType const& value);
/*! /*!
* Retrieves the key stored in the given bucket (if any) and the value it is mapped to. * Retrieves the key stored in the given bucket (if any) and the value it is mapped to.
* *

Loading…
Cancel
Save