Stream: show and tell

Topic: SimpleHasher


view this post on Zulip Luke Boswell (Nov 25 2023 at 06:05):

I need a hasher for something I'm working on and put this SimpleHasher together.

It only XORs the current hash with the new content, which is probably not very resistant to collisions, but seems to work OK for what I need.

view this post on Zulip Luke Boswell (Nov 25 2023 at 06:05):

expect hasher 0 |> Hash.hash 12u8 |> Hash.complete == 12u64
expect hasher 0 |> Hash.hash (SomeTag 42) |> Hash.complete == 42u64
expect hasher 0 |> Hash.hash { a: 84, b: "x", c: Yellow "Submarine" } |> Hash.complete == 4976968789605u64
expect hasher 0 |> Hash.hash "SomeString" |> Hash.complete == 3681188331052135u64

view this post on Zulip Luke Boswell (Nov 25 2023 at 06:07):

If someone with a deeper appreciation for the mathematics improves on this, I'd be keen to use it :smiley:

view this post on Zulip Brendan Hansknecht (Nov 25 2023 at 06:37):

You could steal the standard library impl, just fork that. It should be a nice hash, but depends on the exact goals

view this post on Zulip Luke Boswell (Nov 25 2023 at 07:11):

Oh neat. I hadn't noticed that before. Now I know what I'm looking at I can see it.

view this post on Zulip Brendan Hansknecht (Nov 25 2023 at 07:12):

Might even be worth releasing as a wyhash package


Last updated: Jul 06 2025 at 12:14 UTC