-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] generic over the hash function #1
Comments
Thanks for the request @peter7891! There are a few things to consider when choosing a hash function for a hash table. Hash functions with a poor output distribution can quickly degrade the performance of the hash table. This is especially true with closed-hashing hash tables and tables that use linear probing to resolve collisions (both apply to SwissMap). Secondly, if the hash function is not properly seeded, it can be susceptible to a hash-flooding attack. There's a tradeoff between giving users more flexibility/choice and giving them enough rope to hang themselves. An argument against exposing custom hash functions is that the default hash is both fast and high quality. It's the same hash function used by the built in That said, I'm happy to hear other opinions and discuss further |
You are probably right. The Go compiler doesn't do many optimizations so its probably futile to try to optimize it. |
I wrote some microbenchmarks to compare a few potential hash functions. The current hash function is
|
That looks pretty good. |
@andy-wm-arthur Just adding my 2-cents to this. We are using Swiss Map with keys that are already hashed and very evenly distributed. Our keys are |
If you look at the Rust api for
std::collections::HashMap
it is generic over the hashing function.This is very useful for people to be able to choose, based on whether they care more about speed than security in the particular functionality they are using the map in.
I think, this would be a good feature to have here.
The text was updated successfully, but these errors were encountered: