Skip to content
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

Added .hash() functions for vectors #2043

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sandervdbosch
Copy link
Contributor

Currently only vectors up to 16 bytes in size can be used in a Hashmap due to the requirement of $Type.alignof <= mem::DEFAULT_MEM_ALIGNMENT on allocator:new
I recon allowing for larger types would require changes to the Hashmap module.

Suggestions on how to improve the functionalities are welcome.

@lerno
Copy link
Collaborator

lerno commented Mar 13, 2025

This looks wrong. You're hashing the vectors on their pointer, not on their content.

@sandervdbosch
Copy link
Contributor Author

It should be fixed now. I also added support for arrays of all the normal types.

@lerno
Copy link
Collaborator

lerno commented Mar 14, 2025

For the tests you want to create two vectors separately but with the same values and check that they give the same hash.

@sandervdbosch
Copy link
Contributor Author

I did do that in a test program I wrote, but since the normal hash functions did not do this I hadn't added it to the test yet.

@sandervdbosch sandervdbosch marked this pull request as ready for review March 15, 2025 15:18
macro uint uint128.hash(uint128 i) => @generic_hash(i);
macro uint uint128[<*>].hash(uint128[<*>] i) => (uint)fnv32a::hash(((char*)&&i)[:$sizeof(i[0])*i.len]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space between operators to keep the code consistent, e.g. $sizeof(i[0]) * i.len

@lerno
Copy link
Collaborator

lerno commented Mar 20, 2025

If you take the address of char/ichar arrays / vectors they can be cast to a char[] and directly handed over to the hash function. No need to bitcast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants