notify.moe/utils/HashStrings.go

25 lines
488 B
Go
Raw Normal View History

2018-03-09 05:12:22 +01:00
package utils
import "github.com/OneOfOne/xxhash"
2018-03-09 13:42:45 +01:00
// HashString returns a hash of the string.
func HashString(item string) uint64 {
h := xxhash.NewS64(0)
h.Write([]byte(item))
return h.Sum64()
}
2018-03-09 05:12:22 +01:00
// HashStringsNoOrder returns a hash of the string slice contents, ignoring order.
func HashStringsNoOrder(items []string) uint64 {
sum := uint64(0)
for _, item := range items {
h := xxhash.NewS64(0)
h.Write([]byte(item))
numHash := h.Sum64()
sum += numHash
}
return sum
}