Skip to content

Commit

Permalink
Fix murmur64a hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
xypwn committed Apr 3, 2024
1 parent b068715 commit cfd50d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 0 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ func New(printer *Printer) (*App, error) {
Hashes: make(map[stingray.Hash]string),
}

// HACK: We don't know this hash's source string yet
a.Hashes[stingray.Hash{Value: 0xeac0b497876adedf}] = "material"

return a, nil
}

Expand Down
10 changes: 6 additions & 4 deletions stingray/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Hash struct{ Value uint64 }
// Murmur64a hash
func Sum64(b []byte) Hash {
var seed uint64 = 0
var mix uint64 = 0xC6A4A7935BD1E995
var mix uint64 = 0xc6a4a7935bd1e995
const shifts = 47

var hash uint64 = seed ^ (uint64(len(b)) * mix)
Expand All @@ -27,11 +27,13 @@ func Sum64(b []byte) Hash {
hash *= mix
}

for i := len(b) - 1; i >= 0; i-- {
hash ^= uint64(b[i]) << uint64(8*i)
if len(b) > 0 {
for i := len(b) - 1; i >= 0; i-- {
hash ^= uint64(b[i]) << uint64(8*i)
}
hash *= mix
}

hash *= mix
hash ^= hash >> shifts

hash *= mix
Expand Down

0 comments on commit cfd50d9

Please sign in to comment.