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;
}
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) {
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.");

8
src/storm/storage/BitVector.h

@ -373,6 +373,14 @@ namespace storm {
*/
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
* bit vector.

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

@ -398,6 +398,15 @@ TEST(BitVectorTest, Increment) {
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) {
storm::storage::BitVector vector1(32);
storm::storage::BitVector vector2(32, true);

Loading…
Cancel
Save