\brief A hash function for bitmaps that can handle offsets and lengths in terms of number of bits. The hash only depends on the bits actually hashed. This implementation is based on 64-bit versions of MurmurHash2 by Austin Appleby. It's the caller's responsibility to ensure that bits_offset + num_bits are readable from the bitmap. \param key The pointer to the bitmap. \param seed The seed for t
| 39 | /// \param bits_offset The offset in bits relative to the start of the bitmap. |
| 40 | /// \param num_bits The number of bits after the offset to be hashed. |
| 41 | uint64_t MurmurHashBitmap64(const uint8_t* key, uint64_t seed, uint64_t bits_offset, |
| 42 | uint64_t num_bits) { |
| 43 | const uint64_t m = 0xc6a4a7935bd1e995LLU; |
| 44 | const int r = 47; |
| 45 | |
| 46 | uint64_t h = seed ^ (num_bits * m); |
| 47 | |
| 48 | BitmapWordReader<uint64_t> reader(key, bits_offset, num_bits); |
| 49 | auto nwords = reader.words(); |
| 50 | while (nwords--) { |
| 51 | auto k = reader.NextWord(); |
| 52 | k *= m; |
| 53 | k ^= k >> r; |
| 54 | k *= m; |
| 55 | |
| 56 | h ^= k; |
| 57 | h *= m; |
| 58 | } |
| 59 | int valid_bits; |
| 60 | auto nbytes = reader.trailing_bytes(); |
| 61 | if (nbytes) { |
| 62 | uint64_t k = 0; |
| 63 | do { |
| 64 | auto byte = reader.NextTrailingByte(valid_bits); |
| 65 | k = (k << 8) | static_cast<uint64_t>(byte); |
| 66 | } while (--nbytes); |
| 67 | h ^= k; |
| 68 | h *= m; |
| 69 | } |
| 70 | |
| 71 | h ^= h >> r; |
| 72 | h *= m; |
| 73 | h ^= h >> r; |
| 74 | return h; |
| 75 | } |
| 76 | |
| 77 | } // namespace |
| 78 |
no test coverage detected