Adding updated hashing

This commit is contained in:
2022-10-10 01:28:39 -07:00
parent 8a6b01b55c
commit 5c6cb8e0c9

17
hash.go
View File

@@ -3,6 +3,7 @@ package colorhash
import (
"encoding/binary"
"hash/fnv"
"image/color"
"io"
)
@@ -36,3 +37,19 @@ func HashBytes(r io.Reader) int {
}
return sint
}
func BytesToColor(p ColorSet, r io.Reader) color.Color {
i := HashBytes(r) % p.Len()
return p.Get(i)
}
func StringToColor(p ColorSet, s string) color.Color {
i := HashString(s) % p.Len()
return p.Get(i)
}
func (sp StringerPalette) GetString(s string) string {
h := HashString(s)
h = h % len(sp)
return sp[h](s)
}