-
Notifications
You must be signed in to change notification settings - Fork 297
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
Bucket-based API for HashTable #613
Comments
I think this would help indexmap's |
This assumes that deleting an element doesn't displace other elements, which is currently true but not technically guaranteed, as far as I can tell? |
I think that's correct. |
In theory, insertions could displace existing items as well. The standard library definitely shouldn't make any guarantees about this, but would it be so bad if |
I want to propose the following API for
HashTable
. OnOccupiedEntry
I would like to addOn
HashTable
itself I would like to add the following four functions:There are multiple reasons why I'd like this.
It allows incredibly flexible iteration over the hash table. I am aware that this iteration would be suboptimal compared to a SIMD-based iteration which checks the tags of 16 elements in one go, but the flexibility it provides is well worth it. For example: it makes parallel iteration over the hash table trivial, in whatever permutation you'd like.
It allows intrusive data structures to interweave with the hash table, so long as you are careful to avoid rehashing. An example I ran into recently was the writing of a fixed-capacity LRU cache. When the LRU cache wants to evict the least recently used key it has to do a lookup for that key. It could instead simply store the bucket index and use that to directly remove the key, as the hash table never rehashes in this example.
It allows additional algorithms to run safely and soundly (e.g. no pointers into the hash table which requires unsafe code and which may or may not get invalidated with the latest flavor of stacked/tree borrows) while referring into the hash table. For example: sorting the keys of a hash table while not cloning the keys or taking them out of the table.
The text was updated successfully, but these errors were encountered: