-
Notifications
You must be signed in to change notification settings - Fork 224
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
Ignore discriminants in Hash for AV + ArrayValue
+ nix len-prefix for PV
#1057
Conversation
Hash for AlgebraicValue
to ignore dicriminantsHash for AlgebraicValue
to ignore discriminants
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.
Does this make BFLATN hashing consistent with ProductValue::hash
? I suspect not until we merge #1063 . If that's the case, I'd like to hold off on merging this until after that PR, and then add a (prop)test to this PR that the hash functions are indeed consistent.
I'd also like to see a comment on SumValue
about what constraints need to be upheld by its Hash
impl, and the fact that derive(Hash)
does indeed uphold those constraints.
Otherwise, code looks good. I'll mention that, for our case of comparing hashes only between homogeneously-typed values, this does not actually weaken the hash function at all - in fact, avoiding feeding known-equal data into the hasher should improve the hashes, as we're now packing the same number of "interesting" bits alongside fewer "boring" bits into a hash.
fa485cb
to
fb56a9b
Compare
This does not, but is a stepping stone towards that goal. The full implementation is provided in #1107 with proptests and Note however that #1063, now merged, has no bearing on this or #1107.
Added a larger comment in
Yep, that's definitely true. I'll adjust the PR title and description to capture this. |
Hash for AlgebraicValue
to ignore discriminants Hash for AV + ArrayValue
+ nix len-prefix for PV
- Nix len-prefixing in `Hash for ProductValue` - Ignore discriminants in `Hash for ArrayValue`
fb56a9b
to
919c75b
Compare
Description of Changes
Fixes #1048.
Hash for AV
does not includeDiscriminant<AV>
anymore.Hash for PV
is no longer length-prefixed.Hash for ArrayValue
does not includeDiscriminant<ArrayValue>
anymore.In spacetimedb, we only compare hashes between homogeneously-typed values. Therefore, this PR does less work and does in fact not weaken the hash function. Rather, by avoiding to feed in known-equal data into the hasher, we can reduce the rate of conflicts, as we're now packing the same number of "interesting" bits alongside fewer "boring" bits into a hash.
API and ABI breaking changes
Semantics in the APIs above are broken by this PR.
Expected complexity level and risk
2