struct
Hasher
The universal hash function used by Set
and Dictionary
.
Initializers
Creates a new hasher.
The hasher uses a per-execution seed value that is set during process startup, usually from a high-quality random source.
Declaration
public
init
()
Instance Methods
Adds the given value to this hasher, mixing its essential parts into the hasher state.
- Parameter value: A value to add to the hasher.
Declaration
@
inlinable
public
mutating
func
combine
<
H
>
(
_
value
:
H
)
where
H
:
Hashable
Adds the contents of the given buffer to this hasher, mixing it into the hasher state.
- Parameter bytes: A raw memory buffer.
Declaration
public
mutating
func
combine
(
bytes
:
UnsafeRawBufferPointer
)
Finalizes the hasher state and returns the hash value.
Finalizing consumes the hasher: it is illegal to finalize a hasher you don't own, or to perform operations on a finalized hasher. (These may become compile-time errors in the future.)
Hash values are not guaranteed to be equal across different executions of your program. Do not save hash values to use during a future execution.
Declaration
public
func
finalize
() -
>
Int
Hasher
can be used to map an arbitrary sequence of bytes to an integer hash value. You can feed data to the hasher using a series of calls to mutatingcombine
methods. When you've finished feeding the hasher, the hash value can be retrieved by callingfinalize()
:Within the execution of a Swift program,
Hasher
guarantees that finalizing it will always produce the same hash value as long as it is fed the exact same sequence of bytes. However, the underlying hash algorithm is designed to exhibit avalanche effects: slight changes to the seed or the input byte sequence will typically produce drastic changes in the generated hash value.