Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAtoms: hash table lookup without creating an Atom? #17375
Comments
|
cc: @SimonSapin |
|
The With Stylo we could add FFI bindings to the hashing function (though taking |
|
Is there any way to get them to agree? e.g. by storing the hash value in with the string content, and returning that as the hash? (This does mean an extra pointer indirection when hashing atoms, so may not be worth it.) If we can't get |
|
Sorry, my previous answer was outdated. In the case of static and dynamic atoms we do store a hash based on the string’s bytes since servo/string-cache#183. However for inline atoms there is by definition no data structure on the side where we could store it. As to (This was all about https://github.com/servo/string-cache, I’m less familiar with Gecko atoms.) |
|
Ah, if static and dynamic atoms are already storing the hash, then we could just hash inline atoms based on their string content and get the Atom hash to agree with the &str hash? This would allow Atom to implement |
|
Yes, gecko atoms might be another story :( |
|
Given that the hasher is a type parameter of the Also, the exact behavior of |
|
Oh good point, there are multiple hash functions. We'd have to implement hashing an Atom by hashing its string content, which isn't very efficient. Not sure what to name the function which returns an Atom. Perhaps |
|
@SimonSapin Is this still something we want to do? |
|
I believe making hashing of |
|
Somewhat relatedly, we also have |
If we have a
HashMap<Atom, Foo>it would be nice if we could look up a string without first converting it to anAtom. The best way to do this would be to implementBorrow<str>forAtom, but this requires the hash functions forAtomand&strto agree.