vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

Fingerprint/hash function for strings #403

Open charlesstaats opened 7 months ago

charlesstaats commented 7 months ago

It is generally accepted that fingerprint and hashing functions should be written in fully compiled languages, as they are highly inefficient otherwise.

I request a new Asymptote builtin function to take a fingerprint/hash of a string, for two purposes:

An important detail for the first usage is that it should be possible to use this builtin function to create long enough hashes to all but guarantee uniqueness (since having a filename collision would likely cause an error rather than just a slightly longer running time). I recommend https://github.com/google/highwayhash as a library that can provide fast, high-quality hashes in C/C++ up to 256 bits.

For the exact signature of the builtin, I recommend returning an array of ints (each having 32 bits of information, since Asymptote has no uint64 type). Potentially, the length of the returned array could depend on a user-provided parameter, so that extra effort is not used to compute unneeded bits.