[std]: Use XXHash64 instead FNV-1a#1581
[std]: Use XXHash64 instead FNV-1a#1581MaxGraey wants to merge 12 commits intoAssemblyScript:mainfrom MaxGraey:xxhash64
Conversation
| // buckets referencing their respective first entry, usize[bucketsMask + 1] | ||
| private buckets: ArrayBuffer = new ArrayBuffer(INITIAL_CAPACITY * <i32>BUCKET_SIZE); | ||
| private bucketsMask: u32 = INITIAL_CAPACITY - 1; | ||
| private bucketsMask: u64 = INITIAL_CAPACITY - 1; |
There was a problem hiding this comment.
I am a bit confused by the u32/u64 changes in Map and Set. For instance, u64 isn't really necessary here given that ArrayBuffer capacity is capped, but also may make sense given that hashes are 64-bit now, not sure. But then, further down below, we still have rehash(newBucketsMask: u32) or halfBucketsMask = <u32>(this.bucketsMask >> 1). Now, just using usize as a workaround also doesn't seem quite right, hmm. A strange mix.
There was a problem hiding this comment.
I tied just truncate u64 result to u32 inside hashes but it looks less optimal with more u64 -> u32 conversions
There was a problem hiding this comment.
I think this makes me a bit in favor of the 32-bit variant for now. Would you agree with a plan like, let's use 32-bit now, and once we have Memory64 support, revisit 64-bit? Iirc that's about what you suggested earlier as well (sorry).
There was a problem hiding this comment.
yeah, I'm ok with that. Will sync XXH32
| v = (v ^ <u32>load<u8>(changetype<usize>(key) + i)) * FNV_PRIME; | ||
| // @ts-ignore: decorator | ||
| @inline | ||
| function hashStr(key: string): u64 { |
There was a problem hiding this comment.
Do you have a reference for the code in this function?
There was a problem hiding this comment.
It's loosely based on this: https://github.com/Cyan4973/xxHash/blob/dev/xxhash.h
|
This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions! |
|
This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards. |
This experiment with XXHash 64-bit hashes
See 32-bit here: #1580
FNV-1a:
XXHash:
Excellent uniform distribution
Near-perfect avalanche effect
Speed: ~1.7 cyclers per byte
I've read the contributing guidelines