-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add Equivalence
trait
#45
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of thoughts. If we do end up adding this method, we should probably also add a hasher
accessor method to HashMap
.
src/map.rs
Outdated
/// satisfies the equality function passed. | ||
/// | ||
/// This function is similar to [`Self::get()`], but provides a shortcut | ||
/// for lookups where instantiation of keys is expensive. For instance, if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this use case be better served by the Equivalent
trait? get_by_hash
is useful but I think serves a different use case, such as supporting unhashable types or precomputed hashes. For that I wonder if it would be better to expose a lower-level type such as hashbrown's HashTable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point! I've switched to using an Equivalent
trait instead, so we don't need an additional method. This also leaves fewer opportunities for consumers to misuse the API.
src/raw/mod.rs
Outdated
/// ## Contract | ||
/// | ||
/// The implementor must hash like K, if it is hashable. | ||
pub trait Equivalent<K> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to just pull in the equivalent
crate for this instead.
Just doing a ctrl+f for uses of |
Thanks again for the review, both are done! |
Perfect, thanks! |
Released in 0.1.8. |
This PR adds
get_by_hash()
methods that allow for faster lookups when instantiating keys is expensive.I figured I could get away without writing tests, since the implementation of
get()
now uses this method internally, so it's implicitly covered :)