mirror of
https://github.com/taigrr/colorhash.git
synced 2026-04-01 18:58:45 -07:00
Adding updated hashing
This commit is contained in:
17
hash.go
17
hash.go
@@ -3,6 +3,7 @@ package colorhash
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
|
"image/color"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,3 +37,19 @@ func HashBytes(r io.Reader) int {
|
|||||||
}
|
}
|
||||||
return sint
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user