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

Add a hash function #406

Closed
wants to merge 74 commits into from
Closed

Add a hash function #406

wants to merge 74 commits into from

Conversation

charlesstaats
Copy link
Contributor

Add a hash function for strings. This hash function is based on std::hash, but with two notes:

  • To get a 62-bit hash (which is the largest number of bits in Asymptote such that every possible bitstring can be represented as a positive int), the two most-significant bits are first XOR'd with the two least significant bits.
  • Since std::hash is implementation-defined, its values are likely to change from time to time, and may also differ e.g. across operating systems. To prevent users from coming to rely on a consistent but not-promised behavior, the hash is also XOR'd with a 62-bit integer that is randomly chosen each time asy starts up (but remains consistent throughout a single run of asy). A try_consistent option is available for users who want to disable this enforced inconsistency.

The result is a new builtin function <int hash(string s, bool try_consistent=<default>)>.

@charlesstaats charlesstaats linked an issue Dec 21, 2023 that may be closed by this pull request
@user202729
Copy link

If we have taken the effort to write such a thing, why not make it cryptographically secure? (might need an extra dependency on OpenSSL though for maybe SHA256?)

@charlesstaats
Copy link
Contributor Author

I ended up adding a bunch more commits to this branch, so this pull request no longer really makes sense.

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.

Fingerprint/hash function for strings
3 participants