-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Provider stronger hash codes #39
Comments
Hi @davidmorgan 👋 You bring up a great point and we can definitely make this improvement. I would love to review a pull request if you want to contribute or alternatively, I can try to make this adjustment over the next few days 👍 Thanks again! |
I currently have a cold so I'm sticking to email right now ;) BTW, the reason I was looking into this is I'm considering proposing a lint recommending that people not implement I wonder if you know of any others? |
@davidmorgan hope you feel better! That's awesome, I think a lint would be really nice to have. I honestly only know of BTW I was thinking about your proposal and am wondering if there's a concrete use-case where XOR would not work? I agree that it theoretically doesn't satisfy all cases, but given the props override is part of the class implementation I don't think there would be a problem unless props dynamically builds the list and the order changes at runtime and even then I created a gist to test this behavior and it seems to work fine unless I'm missing something. Thoughts? |
The problem is that naturally occurring data might lead to a large number of hash collisions. For example, if you have a
then these eight objects hash to only four hash codes. Another natural example would be if you have one field for first name, one field for last name; and then someone called Jenkins hash should be very fast to compute--just a little slower than xor by itself--but distributes the hash keys much more evenly, pretty much removing cases where particular patterns in the data can lead to hash collisions. (i.e. the data that leads to hash collisions looks like random data, and you can only hit it either by coincidence--rare enough that it doesn't matter--or by malicious input crafted to cause hash collisions--which is a whole other conversation). |
Makes sense, thanks for clarifying 💯 |
Done in #40 and will be released as part of v1.0.0 |
Thank you @davidmorgan for improvements! |
Awesome, thanks! |
I was looking for ways to ease
operator ==
andhashCode
in Dart and found equatable.It seems a reasonable approach overall.
But, looking at the implementation, it looks like it uses XOR to combine hashes. This would mean, for example, that
and
will hash to the same value. Did I miss something?
I think the correct approach would be to use something like
https://en.wikipedia.org/wiki/Jenkins_hash_function
--which is what
package:quiver
useshttps://github.com/google/quiver-dart/blob/master/lib/src/core/hash.dart
Good news is it should be possible to add this within the current implementation with no changes to how it's used :)
Thanks!
The text was updated successfully, but these errors were encountered: