Skip to content

Commit

Permalink
Merge pull request #100 from neilalexander/master
Browse files Browse the repository at this point in the history
Fix hashing on big-endian systems
  • Loading branch information
lemire authored Mar 16, 2024
2 parents 55a408e + 685ed1c commit 1b8b697
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions murmur.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package bloom

import (
"encoding/binary"
"math/bits"
"unsafe"
)
Expand All @@ -59,8 +60,8 @@ type digest128 struct {
func (d *digest128) bmix(p []byte) {
nblocks := len(p) / block_size
for i := 0; i < nblocks; i++ {
t := (*[2]uint64)(unsafe.Pointer(&p[i*block_size]))
k1, k2 := t[0], t[1]
b := (*[16]byte)(unsafe.Pointer(&p[i*block_size]))
k1, k2 := binary.LittleEndian.Uint64(b[:8]), binary.LittleEndian.Uint64(b[8:])
d.bmix_words(k1, k2)
}
}
Expand Down Expand Up @@ -269,8 +270,8 @@ func (d *digest128) sum256(data []byte) (hash1, hash2, hash3, hash4 uint64) {
// we do not want to append to an actual array!!!
if tail_length+1 == block_size {
// We are left with no tail!!!
word1 := *(*uint64)(unsafe.Pointer(&tail[0]))
word2 := uint64(*(*uint32)(unsafe.Pointer(&tail[8])))
word1 := binary.LittleEndian.Uint64(tail[:8])
word2 := uint64(binary.LittleEndian.Uint32(tail[8 : 8+4]))
word2 = word2 | (uint64(tail[12]) << 32) | (uint64(tail[13]) << 40) | (uint64(tail[14]) << 48)
// We append 1.
word2 = word2 | (uint64(1) << 56)
Expand Down

0 comments on commit 1b8b697

Please sign in to comment.