Browse Source

adding murmur3 as a possible hash fct for bit vectors

tempestpy_adaptions
dehnert 7 years ago
parent
commit
8b557c36a7
  1. 60
      src/storm/storage/BitVector.cpp
  2. 5
      src/storm/storage/BitVector.h
  3. 3
      src/storm/storage/BitVectorHashMap.h

60
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<unsigned char const*>(bv.buckets);
unsigned char const* ite = it + 8 * bv.bucketCount();
uint8_t* it = reinterpret_cast<uint8_t*>(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<uint8_t const*>(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<uint32_t const*>(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<uint_fast64_t>::iterator begin, std::vector<uint_fast64_t>::iterator end);
template BitVector::BitVector(uint_fast64_t length, std::vector<uint_fast64_t>::const_iterator begin, std::vector<uint_fast64_t>::const_iterator end);

5
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<storm::storage::BitVector>;
friend struct FNV1aBitVectorHash;
friend struct Murmur3_32_BitVectorHash;
private:
/*!
@ -575,6 +576,10 @@ namespace storm {
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

3
src/storm/storage/BitVectorHashMap.h

@ -15,7 +15,8 @@ namespace storm {
* 64.
*/
// template<typename ValueType, typename Hash = std::hash<storm::storage::BitVector>>
template<typename ValueType, typename Hash = FNV1aBitVectorHash>
// template<typename ValueType, typename Hash = FNV1aBitVectorHash>
template<typename ValueType, typename Hash = Murmur3_32_BitVectorHash>
class BitVectorHashMap {
public:
class BitVectorHashMapIterator {

Loading…
Cancel
Save