3 ms·
The hasher in the standard library is defined here: https://github.com/apple/swift/blob/master/stdlib/public/core/Hasher.swift#L252,L294 https://github.com/appl
by rokob 8y ago
The hasher in the standard library is defined here:
https://github.com/apple/swift/blob/master/stdlib/public/core/Hasher.swift#L252,L294 https://github.com/apple/swift/blob/master/stdlib/public/cor...
with some explanation for where the seed comes from here:
https://github.com/apple/swift/blob/master/stdlib/public/core/Hasher.swift#L310,L324 https://github.com/apple/swift/blob/master/stdlib/public/cor...
Within that code you will see references to Core which by default is this:
https://github.com/apple/swift/blob/82226642c2459c0f5d2054fe1f6545b57efafffb/stdlib/public/core/SipHash.swift https://github.com/apple/swift/blob/82226642c2459c0f5d2054fe...
So you can see the hash function itself is deterministic given the seed it is initialized with. And the seed is generated at process start time during static initialization in C++ so it is effectively a constant for the lifetime of the process.
You can see in the code that there is a way to make hashing fully deterministic by making the seed generation not use random numbers, but it is ill-advised for a variety of security reasons.