dgraph-io / ristretto

A high performance memory-bound Go cache

Home Page:https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to specify custom hashing functions

GiedriusS opened this issue · comments

Currently here https://github.com/dgraph-io/ristretto/blob/master/z/z.go#L20 all of the possible types are written out. However, users like me may want to use a "custom" struct as a key but that does not work at the moment since it is not written there and then my whole program panics.

I propose the following: add some kind of "advanced" option to the library which is a function (func (key interface{}) (uint64, error)) which accepts the key (interface{}) and produces a uint64 hash. It then could be called in the default case. If an error happens - only then we should panic.

What do you think?