Browse Source

permute for bitvectors

tempestpy_adaptions
Sebastian Junges 5 years ago
parent
commit
0dd15b4e2f
  1. 10
      src/storm/storage/BitVector.cpp
  2. 8
      src/storm/storage/BitVector.h
  3. 9
      src/test/storm/storage/BitVectorTest.cpp

10
src/storm/storage/BitVector.cpp

@ -433,6 +433,16 @@ namespace storm {
return true; return true;
} }
BitVector BitVector::permute(std::vector<uint64_t> const& inversePermutation) const {
BitVector result(this->size());
for (uint64_t i = 0; i < this->size(); ++i) {
if(this->get(inversePermutation[i])) {
result.set(i, true);
}
}
return result;
}
void BitVector::set(uint_fast64_t bitIndex, BitVector const& other) { void BitVector::set(uint_fast64_t bitIndex, BitVector const& other) {
STORM_LOG_ASSERT((bitIndex & mod64mask) == 0, "Bit index must be a multiple of 64."); STORM_LOG_ASSERT((bitIndex & mod64mask) == 0, "Bit index must be a multiple of 64.");
STORM_LOG_ASSERT(other.size() <= this->size() - bitIndex, "Bit vector argument is too long."); STORM_LOG_ASSERT(other.size() <= this->size() - bitIndex, "Bit vector argument is too long.");

8
src/storm/storage/BitVector.h

@ -372,6 +372,14 @@ namespace storm {
* @param other The bit vector whose pattern to set. * @param other The bit vector whose pattern to set.
*/ */
void set(uint_fast64_t bitIndex, BitVector const& other); void set(uint_fast64_t bitIndex, BitVector const& other);
/*!
* Apply a permutation of entries. That is, in row i, write the entry of row inversePermutation[i].
* @param inversePermutation.
* @return
* TODO this operation is slow.
*/
BitVector permute(std::vector<uint64_t> const& inversePermutation) const;
/*! /*!
* Retrieves the content of the current bit vector at the given index for the given number of bits as a new * Retrieves the content of the current bit vector at the given index for the given number of bits as a new

9
src/test/storm/storage/BitVectorTest.cpp

@ -398,6 +398,15 @@ TEST(BitVectorTest, Increment) {
EXPECT_TRUE(vector1.empty()); EXPECT_TRUE(vector1.empty());
} }
TEST(BitVectorTest, permute) {
storm::storage::BitVector vector1(9, {3, 5});
std::vector<uint64_t> inversePermutation = {0, 1, 3, 2, 4, 6, 5, 8, 7};
storm::storage::BitVector vector2 = vector1.permute(inversePermutation);
EXPECT_EQ(vector1.getNumberOfSetBits(), vector2.getNumberOfSetBits());
EXPECT_TRUE(vector2.get(2));
EXPECT_TRUE(vector2.get(6));
}
TEST(BitVectorTest, Implies) { TEST(BitVectorTest, Implies) {
storm::storage::BitVector vector1(32); storm::storage::BitVector vector1(32);
storm::storage::BitVector vector2(32, true); storm::storage::BitVector vector2(32, true);

Loading…
Cancel
Save