From 8b557c36a798e1bc337644a096c7aa6476d2b62d Mon Sep 17 00:00:00 2001 From: dehnert Date: Tue, 14 Nov 2017 16:36:52 +0100 Subject: [PATCH] adding murmur3 as a possible hash fct for bit vectors --- src/storm/storage/BitVector.cpp | 60 +++++++++++++++++++++++++++- src/storm/storage/BitVector.h | 7 +++- src/storm/storage/BitVectorHashMap.h | 3 +- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/storm/storage/BitVector.cpp b/src/storm/storage/BitVector.cpp index 924657b44..3b3f9c478 100644 --- a/src/storm/storage/BitVector.cpp +++ b/src/storm/storage/BitVector.cpp @@ -1005,8 +1005,8 @@ namespace storm { std::size_t FNV1aBitVectorHash::operator()(storm::storage::BitVector const& bv) const { std::size_t seed = 14695981039346656037ull; - unsigned char const* it = reinterpret_cast(bv.buckets); - unsigned char const* ite = it + 8 * bv.bucketCount(); + uint8_t* it = reinterpret_cast(bv.buckets); + uint8_t const* ite = it + 8 * bv.bucketCount(); while (it < ite) { seed ^= *it++; @@ -1018,6 +1018,62 @@ namespace storm { return seed; } + inline __attribute__((always_inline)) uint32_t fmix32 (uint32_t h) { + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + + return h; + } + + inline uint32_t rotl32(uint32_t x, int8_t r) { + return (x << r) | (x >> (32 - r)); + } + + inline __attribute__((always_inline)) uint32_t getblock32 (uint32_t const* p, int i) { + return p[i]; + } + + std::size_t Murmur3_32_BitVectorHash::operator()(storm::storage::BitVector const& bv) const { + const uint8_t * data = reinterpret_cast(bv.buckets); + uint32_t len = bv.bucketCount() * 8; + const int nblocks = bv.bucketCount() * 2; + + // Using 0 as seed. + uint32_t h1 = 0; + + const uint32_t c1 = 0xcc9e2d51; + const uint32_t c2 = 0x1b873593; + + //---------- + // body + + const uint32_t * blocks = reinterpret_cast(data + nblocks*4); + + for (int i = -nblocks; i; i++) { + uint32_t k1 = getblock32(blocks, i); + + k1 *= c1; + k1 = rotl32(k1,15); + k1 *= c2; + + h1 ^= k1; + h1 = rotl32(h1,13); + h1 = h1*5+0xe6546b64; + } + + //---------- + // finalization + + h1 ^= len; + + h1 = fmix32(h1); + + return h1; + } + // All necessary explicit template instantiations. template BitVector::BitVector(uint_fast64_t length, std::vector::iterator begin, std::vector::iterator end); template BitVector::BitVector(uint_fast64_t length, std::vector::const_iterator begin, std::vector::const_iterator end); diff --git a/src/storm/storage/BitVector.h b/src/storm/storage/BitVector.h index 17d470eab..8a5c07719 100644 --- a/src/storm/storage/BitVector.h +++ b/src/storm/storage/BitVector.h @@ -502,6 +502,7 @@ namespace storm { friend std::ostream& operator<<(std::ostream& out, BitVector const& bitVector); friend struct std::hash; friend struct FNV1aBitVectorHash; + friend struct Murmur3_32_BitVectorHash; private: /*! @@ -574,7 +575,11 @@ namespace storm { struct FNV1aBitVectorHash { std::size_t operator()(storm::storage::BitVector const& bv) const; }; - + + struct Murmur3_32_BitVectorHash { + std::size_t operator()(storm::storage::BitVector const& bv) const; + }; + } // namespace storage } // namespace storm diff --git a/src/storm/storage/BitVectorHashMap.h b/src/storm/storage/BitVectorHashMap.h index 28eb6c187..ba76e0504 100644 --- a/src/storm/storage/BitVectorHashMap.h +++ b/src/storm/storage/BitVectorHashMap.h @@ -15,7 +15,8 @@ namespace storm { * 64. */ // template> - template +// template + template class BitVectorHashMap { public: class BitVectorHashMapIterator {