-
Notifications
You must be signed in to change notification settings - Fork 165
Expose RawEntry API #166
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
Comments
I am sympathetic to this, but I'd really like to see the API stabilized in |
@cuviper can it be enabled with something like |
In retrospect, there is a way around this:
The function signature on pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
where
Q: Hash + Equivalent<T>, There's a blanket impl Equivalent<MyBigStruct> for HashEssence<'_> {
fn equivalent(&self, big: &MyBigStruct) -> bool {
self.name == big.name && self.source == big.source
}
} |
Equivalent does not help to query with precomputed hashes. Or implement tricky operations like lookup be reference and then insert cloned without computing the hash again. |
Sure, it doesn't solve everything that It's also possible to use something like nohash if you control the I don't like unstable features because if they sit long enough, folks start treating them as de facto stable anyway. But maybe we can compromise by adding an opt-in extension trait, in a similar spirit as I don't want to open the floodgates to start adding all kinds of "unstable" methods this way, but raw entry may be impactful enough to be justified. |
Looks good!
Types like |
Sure, I like that too.
That's possible, though annoying to accomplish with |
I have a usecase for
IndexSet<T>
, whereT
is a complex struct with a hash that is computed on a reduced subset of its fields. I would like to be able to provide just this reduced subset in order to construct a hash and retrieve the stored object, if available.hashbrown
already provides such an option via theRawEntry
API, https://docs.rs/hashbrown/0.9.1/hashbrown/hash_map/struct.HashMap.html#method.raw_entry.HashMap::raw_entry
returns aRawEntryBuilder
object, which in turn exposesRawEntryBuilder::from_hash
, https://docs.rs/hashbrown/0.9.1/hashbrown/hash_map/struct.RawEntryBuilder.html#method.from_hash. This method allows providing just a hash and not the entire object on which the hash is computed.Consider the following example:
Here, the hashes calculated on
HashEssence
andMyBigStruct
are the same. But since I cannotimpl Borrow<HashEssence> for MyBigStruct
, I cannot useIndexSet::get
to pass inHashEssence
. IfIndexSet
exposed a method akin to hashbrown'sRawEntryBuilder
, I could construct aHashEssence
just from two&str
and calculate the hash that way.The text was updated successfully, but these errors were encountered: