Skip to content

Commit

Permalink
Update hash.go
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzotinfena committed Feb 29, 2024
1 parent 32fef94 commit ca3061b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions math/hash.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package math

import (
"fmt"
"bytes"
"encoding/gob"
"hash/fnv"
"reflect"
)

// Non-cryptographic hash (FNV-1a)
func Hash(data any) uint {
f := fnv.New64a()
if reflect.ValueOf(data).Kind() == reflect.Ptr {
f.Write([]byte(fmt.Sprintf("%p", interface{}(data))))
} else {
f.Write([]byte(fmt.Sprintf("%v", data)))
}
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
enc.Encode(data)

Check failure on line 14 in math/hash.go

View workflow job for this annotation

GitHub Actions / Code style and tests

Error return value of `enc.Encode` is not checked (errcheck)
f.Write(buf.Bytes())
return uint(f.Sum64())
}

0 comments on commit ca3061b

Please sign in to comment.