Is there a way to generate the same hash across multiple executions in Swift?

880 Views Asked by At

Apple's Hasher documentation tells that Hasher generates a different hash value on every execution and that hashes shouldn't persist across multiple executions.

Do not save or otherwise reuse hash values across executions of your program. Hasher is usually randomly seeded, which means it will return different values on every new execution of your program. The hash algorithm implemented by Hasher may itself change between any two versions of the standard library.

I do need, however, a way to generate a hash that is reproducible across multiple sessions. I am trying to use the hash value to differentiate between labels of a hashable structure. Since the input data may come from different executions, hashes wouldn't match if I used Hasher and Hashable.

I've considered writing an implementation of a murmur hashing algorithm, but those generally apply to string values, not optional structures.

Is there an alternative to Hasher in Swift that I could use to get reproducible hashes with arbitrary structures? Is there a hashing function that accepts a starting seed?

Thank you for your help!

0

There are 0 best solutions below