In documentation String.hash
for iOS it says:
You should not rely on this property having the same hash value across releases of OS X.
(strange why they speak of OS X in iOS documentation)
Well, I need a hasshing function that will not change with iOS releases. It can be simple I do not need anything like SHA. Is there some library for that?
There is another question about this here but the accepted (and only) answer there simply states that we should respect the note in documentation.
Here is a non-crypto hash, for Swift 3:
It was derived somewhat from a C++11 constexpr
Unfortunately, the two don't yield the same hash. To do that you'd need to reverse the iterator order in strHash:
But that will run 13x slower, somewhat comparable to the djb2hash String extension that I got from https://useyourloaf.com/blog/swift-hashable/
Here are some benchmarks, for a million iterations:
For C++, the str2Int is roughly as fast as Swift 3's hashValue: