diff --git a/src/storm/storage/BitVector.cpp b/src/storm/storage/BitVector.cpp index b0a7f9556..11abda87d 100644 --- a/src/storm/storage/BitVector.cpp +++ b/src/storm/storage/BitVector.cpp @@ -261,6 +261,23 @@ namespace storm { truncateLastBucket(); } } + + void BitVector::concat(BitVector const& other) { + STORM_LOG_ASSERT(size() % 64 == 0, "We expect the length of the left bitvector to be a multiple of 64."); + // TODO this assumption is due to the implementation of BitVector::set(). + BitVector tmp(size() + other.size()); + tmp.set(size(), other); + resize(size() + other.size(), false); + *this |= tmp; + } + + void BitVector::expandSize(bool init) { + //size_t oldBitCount = bitCount; + bitCount = bucketCount() * 64; + if (init) { + STORM_LOG_ASSERT(false, "Not implemented as we do not foresee any need"); + } + } void BitVector::grow(uint_fast64_t minimumLength, bool init) { if (minimumLength > bitCount) { diff --git a/src/storm/storage/BitVector.h b/src/storm/storage/BitVector.h index 9561895a8..2980c29cd 100644 --- a/src/storm/storage/BitVector.h +++ b/src/storm/storage/BitVector.h @@ -233,6 +233,19 @@ namespace storm { * @param init The truth value to which to initialize newly created bits. */ void resize(uint_fast64_t newLength, bool init = false); + + /*! + * Concatenate this bitvector with another bitvector. The result is stored in this bitvector. + * During the operation, the bitvector is extended to match the size of the sum of the two bitvectors + * The current implementation expects this->size() to be a multiple of 64. This can be ensured by a call to + * expandSize + */ + void concat(BitVector const& extension); + + /* + * Expands the size to a multiple of 64. + */ + void expandSize(bool init = false); /*! * Enlarges the bit vector such that it holds at least the given number of bits (but possibly more). @@ -424,7 +437,7 @@ namespace storm { bool empty() const; /*! - * Retrievs whether all bits are set in this bit vector. + * Retrieves whether all bits are set in this bit vector. * If the bit vector has size 0, this method always returns true. * * @return True iff all bits in the bit vector are set. diff --git a/src/test/storm/storage/BitVectorTest.cpp b/src/test/storm/storage/BitVectorTest.cpp index d3b65e04c..c2446fa63 100644 --- a/src/test/storm/storage/BitVectorTest.cpp +++ b/src/test/storm/storage/BitVectorTest.cpp @@ -214,7 +214,6 @@ TEST(BitVectorTest, OperatorAnd) { vector2.set(31); storm::storage::BitVector andResult = vector1 & vector2; - for (uint_fast64_t i = 0; i < 31; ++i) { ASSERT_FALSE(andResult.get(i)); } @@ -573,3 +572,27 @@ TEST(BitVectorTest, CompareAndSwap) { result = vector.compareAndSwap(68, 0, 68); ASSERT_TRUE(result); } + +TEST(BitVectorTest, Concat) { + storm::storage::BitVector vector1(64, {3, 5}); + storm::storage::BitVector vector2(65, {10, 12}); + + vector1.concat(vector2); + ASSERT_EQ(129ul, vector1.size()); + ASSERT_TRUE(vector1.get(3)); + ASSERT_TRUE(vector1.get(5)); + ASSERT_TRUE(vector1.get(10 + 64)); + ASSERT_TRUE(vector1.get(12 + 64)); + ASSERT_EQ(4ul, vector1.getNumberOfSetBits()); +} + +TEST(BitVectorTest, Expand) { + storm::storage::BitVector vector1(64, {3, 5}); + vector1.expandSize(); + ASSERT_EQ(64ul, vector1.size()); + ASSERT_EQ(2ul, vector1.getNumberOfSetBits()); + storm::storage::BitVector vector2(65, {10, 12}); + vector2.expandSize(); + ASSERT_EQ(128ul, vector2.size()); + ASSERT_EQ(2ul, vector2.getNumberOfSetBits()); +}