From 0a5717aee704f6529daadcd0566d67f64fefcd20 Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Sat, 2 May 2020 18:56:33 -0700 Subject: [PATCH] lowlevel storing/loading bitvectors from a string (without any error handling, that is). Helpful to store bitvecots in python --- src/storm/storage/BitVector.cpp | 30 ++++++++++++++++++++++++++++++ src/storm/storage/BitVector.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/src/storm/storage/BitVector.cpp b/src/storm/storage/BitVector.cpp index 8df237df3..6edf61f1b 100644 --- a/src/storm/storage/BitVector.cpp +++ b/src/storm/storage/BitVector.cpp @@ -1240,6 +1240,36 @@ namespace storm { return h1 ^ h2; } + + void BitVector::store(std::ostream& os) const { + os << bitCount; + for (uint64_t i = 0; i < bucketCount(); ++i) { + os << " " << buckets[i]; + } + } + + BitVector BitVector::load(std::string const& description) { + std::vector splitted; + std::stringstream ss(description); + ss >> std::noskipws; + std::string field; + char ws_delim; + while(true) { + if( ss >> field ) + splitted.push_back(field); + else if (ss.eof()) + break; + else + splitted.push_back(std::string()); + ss.clear(); + ss >> ws_delim; + } + BitVector bv(std::stoul(splitted[0])); + for(uint64_t i = 0; i < splitted.size()-1; ++i) { + bv.buckets[i] = std::stoul(splitted[i+1]); + } + return bv; + } // All necessary explicit template instantiations. template BitVector::BitVector(uint_fast64_t length, std::vector::iterator begin, std::vector::iterator end); diff --git a/src/storm/storage/BitVector.h b/src/storm/storage/BitVector.h index 64b823652..323020b48 100644 --- a/src/storm/storage/BitVector.h +++ b/src/storm/storage/BitVector.h @@ -538,6 +538,9 @@ namespace storm { friend std::ostream& operator<<(std::ostream& out, BitVector const& bitVector); + void store(std::ostream&) const; + static BitVector load(std::string const& description); + friend struct std::hash; friend struct FNV1aBitVectorHash;