From 8a77228e32dcf4930d31629e15a28f07145f41d5 Mon Sep 17 00:00:00 2001
From: Mavo <matthias.volk@rwth-aachen.de>
Date: Wed, 24 Feb 2016 13:28:13 +0100
Subject: [PATCH] Set value in BitVectorHashMap

Former-commit-id: 2083df9c4abfa5484a694b59bc5e63be41361146
---
 src/storage/BitVectorHashMap.cpp | 24 ++++++++++++++++++++++++
 src/storage/BitVectorHashMap.h   | 19 +++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/storage/BitVectorHashMap.cpp b/src/storage/BitVectorHashMap.cpp
index 4d6238350..08875af3b 100644
--- a/src/storage/BitVectorHashMap.cpp
+++ b/src/storage/BitVectorHashMap.cpp
@@ -140,6 +140,11 @@ namespace storm {
             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>
         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.
@@ -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>
         ValueType BitVectorHashMap<ValueType, Hash1, Hash2>::getValue(storm::storage::BitVector const& key) const {
             std::pair<bool, std::size_t> flagBucketPair = this->findBucket(key);
diff --git a/src/storage/BitVectorHashMap.h b/src/storage/BitVectorHashMap.h
index d50dac59e..18ca52186 100644
--- a/src/storage/BitVectorHashMap.h
+++ b/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.
              */
             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
@@ -79,6 +88,16 @@ namespace storm {
              */
             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.
              *