You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i was looking for hash function implementation using maphash and found your repo
there is a hash method of Map in file maps/hash/hash.go
if you use integer type as comparable K key, you get a panic panic: interface conversion: interface {} is int, not []uint8
it is also panics if key is any Number type, like float64 or uint16
i believe, error in the byte conversion: bytes := any(key).([]byte)
The text was updated successfully, but these errors were encountered:
I would not recommend using this repository for anything in production at this point, many of the collections are unimplemented or untested. Regardless, I will work on fixing this particular issue in case you end up using it, and I am thinking the right approach will look something like this:
func (m*Map) hash(keyK) int {
keyString:=fmt.Sprint(key)
m.Hash.WriteString(keyString)
returnint(m.Hash.Sum64() %len(*m.Vector))
}
thanks for reply and sorry for misunderstanding, i don't use this in production, i was looking specifically for a way to take a hash function from any type (i mean, comparable type)
fortunately i found solution working for me, in this case we can use gob encoder to get byte slice something like this:
func newHashFunc[K comparable]() func(K) uint64 {
var h maphash.Hash
h.SetSeed(maphash.MakeSeed())
var buf bytes.Buffer
encoder := gob.NewEncoder(&buf)
return func(key K) uint64 {
h.Reset()
buf.Reset()
_ = encoder.Encode(key)
_, _ = h.Write(buf.Bytes())
value := h.Sum64()
return value
}
}
i was looking for hash function implementation using maphash and found your repo
there is a
hash
method of Map in filemaps/hash/hash.go
if you use integer type as comparable K key, you get a panic
panic: interface conversion: interface {} is int, not []uint8
it is also panics if key is any Number type, like float64 or uint16
i believe, error in the byte conversion:
bytes := any(key).([]byte)
The text was updated successfully, but these errors were encountered: