-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Equiv and HashMap need a better interface #12135
Comments
Some thought on the HashMap design: How about making HashMap accept an optional comparator for arguments? Every method in HashMap starts with finding the slot by some key, so that's what really has to be refactored. So the HashMap signature may read impl<K:Hash+Eq,V> HashMap<K,V,K,Eq<K>> {
pub fn into_equiv<ArgKey>(self) -> HashMap<K,V,ArgKey,Equiv<ArgKey>> { ... }
} This won't change the casual use of |
@pcwalton has an interesting use case for Equiv-based lookups: in servo they have a hashtable that is constructed using a case-insensitive hash, but then they do case-sensitive lookups using a different equality comparator. This use case cannot be accommodated by having a comparator per map. If we had completed DST (#6308), then I was thinking that we could have a hashtable intended for DST keys. The main difference would be that this table's There was a previous proposal (now closed, I think) to just only have the |
If types that implemented But with a more complex signature, it may less easy to understand, with somewhat less specific error messages if there are compiler errors. It also depends on the assumption that the key-equivalent hashes to the same value as the key itself, which is likely but not certain.
|
cc me |
A further note on the option of providing only In some sense, methods like find_equiv are generalizations of find, but the current trait system makes it so that you cannot usefully do If @nikomatsakis's The signature would look something like: fn find<'a, Q>(&'a self, k: &Q) -> Option<&'a V>
where Q: Hash<S>, () : Equiv<K, Q> using the trick of encoding multiparameter typeclasses via impls on the unit type. We'd also have But as @zkamsler says (and @pcwalton pointed out elsewhere), this makes the signature for basic Another possibility might be to provide an additional type parameter to the If that's too complex, yet another option would be to use something like the above generic implementation internally, but expose multiple instances of it. Something like: One other thing: methods like |
@alexcrichton Should we close this in favor of the collections reform metabug #18424 ? |
Closing now that #18910 has landed. |
minor: Add a test for display rendering record variants
[`useless_asref`]: check that the clone receiver is the parameter Fixes rust-lang#12135 There was no check for the receiver of the `clone` call in the map closure. This makes sure that it's a path to the parameter. changelog: [`useless_asref`]: check that the clone receiver is the closure parameter
Right now we have
find_equiv
, but nothing else on the hash map implementation that we have. We have received a few PRs for adding more*_equiv
methods, and we need to decide how these are going to work out.I envision one of three routes to take:
*_equiv
and figure out a better way of not allocating when looking up in maps with keys of~str
find_equiv
*_equiv
variants of all functions.The text was updated successfully, but these errors were encountered: