-
Notifications
You must be signed in to change notification settings - Fork 50
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: HashSet #21
Comments
What is the advantage over just using a |
Well, it would be a Two benefits:
Also, large keys slow down the hashing process even further. |
I mean, wouldn't this be exactly the same as
Maybe a small code example here could help make things clearer. |
You can get some of the way there by using a custom newtype around an With an intrusive hash set, it doesn't have to do any of that: the link can directly store the bucket index, and removing the element can be done safely without having to use the key at all. As an example, I may have an
Now I can create and delete objects, and it's easy to update both sets in the process. If I am indexing more properties, then removing objects gets very slow, as I have to hash many different properties of the same object, and not all of those keys may even be cheap to compute. |
I personally don't think that simply caching the bucket index is worth the complexity of implementing yet another hash table. The cost of looking up an item in the map is generally dwarfed by that of removing an element anyways. As a side note, I just release a new hash table implementation which much faster than the standard library one. You might want to use it if you feel the standard |
I'm not sure that's true? There might be the occasional degenerate case where you have to do a lot of back-shifting of later elements or resize the hash table, but hashing the key is also costly, especially with SipHasher. Ideally it would be possible to share or reuse a base hash table implementation, but even if you think that using a standard HashMap or your hashbrown library is preferable, the ability to use a hashtable in the same way as the other intrusive collections would be much more convenient. Maybe you could consider adding an "intrusive hash table" that still looks up elements by the key, but is more convenient to use than a |
I think what you really want here is a way to customize hash tables with a way to extract a key, sort of like what |
I imagine this could work in much the same way as the
std::collections::HashSet
(in that is uses open addressing) and have the "link" store the index of the bucket an item belongs to.The text was updated successfully, but these errors were encountered: