-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix issues with using WyHash
with std::hash::Hash
#9
Conversation
…and u64::MAX will never exceed it)
} | ||
|
||
while index > 16 { | ||
if length <= 0 { |
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.
Super minor nit, but since len()
returns a usize
, there won't be anything smaller than a 0
here, so can just == 0
. Not too fussed though about this one.
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.
Yeah. Tbh, mostly had that just because all the clauses were length <=
.
Many thanks for the PR, I'll look into this a bit more and probably merge this since correctness is always appreciated (with perf improvements as a plus). The change in output/stability guarantees will necessitate a new major version though, but that's fine by me. |
From what I gather, it should only really be a few instructions faster for the use case of The other optimization opportunity I saw was storing the secret in |
Yup, |
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.
Looks fine to me, documented and tested so no blockers on this one.
While
WyHash
works properly in the use case where a single call towrite
is followed by a call tofinish
, other use cases (such as those that would be caused by aHashMap<(u32, u32), u32, RandomWyHashState>
) often cause some of the input data to be entirely ignored.This modifies the
Hasher
implementation ofWyHash
such that it mixes in thehi
andlo
from previous calls towrite
and related functions usingwymix
before running it again. This keeps the property thatWyHash
generates the same output as the reference implementation when used with a singlewrite
call while making it both faster and more correct for use in a RustHashMap
.Intended guarantees about the hash output: