class StringZillaHasher Use this class when you need to hash data that arrives in chunks or when building up a hash over time.
hash(seed:) computes a fast 64-bit UInt64 hash of the content, with an optional seed.
let h = "the quick brown fox".hash()
let seeded = "the quick brown fox".hash(seed: 42)
assert(h != seeded) // a different seed yields a different hashFor data arriving in chunks, StringZillaHasher hashes incrementally. update(_:) is chainable, finalize() and its alias digest() return the UInt64 without consuming the state, and reset(seed:) restarts it.
let hasher = StringZillaHasher(seed: 0)
hasher.update("the quick ").update("brown fox")
let digest = hasher.finalize()
assert(digest == "the quick brown fox".hash())sha256() returns the SHA-256 digest of the content as a 32-byte [UInt8].
let sum = "hello".sha256() // [UInt8] of length 32
assert(sum.count == 32)The streaming StringZillaSha256 mirrors the incremental hasher. update(_:) accepts either a string view or a [UInt8], finalize() and its alias digest() return the 32-byte digest, hexdigest() returns the 64-character lowercase hex string, and reset() restarts it.
let sha = StringZillaSha256()
sha.update("hello, ").update("world")
let hex = sha.hexdigest() // 64-char hex string
assert(hex.count == 64)StringZillaHasherA progressive hasher for computing StringZilla hashes incrementally.5class StringZillaHasher Use this class when you need to hash data that arrives in chunks or when building up a hash over time.
initCreates a new hasher with the specified seed.init(seed: UInt64 = 0) seed | The seed value for the hash function, defaulting to 0. |
|---|
updateUpdates the hash state with additional string content.@discardableResult func update<S>(_ content: S) -> StringZillaHasher where S : StringZillaViewable content | The string content to add to the hash. |
|---|
finalizeFinalizes the hash computation and returns the result.func finalize() -> UInt64 This is a non-consuming operation and can be called multiple times.
*× 2Alias for finalize().func digest() -> UInt64 resetResets the hasher to its initial state.func reset(seed: UInt64? = nil) seed | New seed value; the original seed is not retained, so omitting this re-seeds with 0. |
|---|
StringZillaSha256A progressive SHA-256 hasher for computing cryptographic checksums incrementally.5class StringZillaSha256 Use this class when you need to hash data that arrives in chunks or when building up a hash over time.
initCreates a new SHA-256 hasher.updateUpdates the hash state with additional data.@discardableResult func update<S>(_ content: S) -> StringZillaSha256 where S : StringZillaViewable @discardableResult func update(_ data: [UInt8]) -> StringZillaSha256 Updates the hash state with raw byte data.
content | The data to add to the hash. | |
|---|---|---|
data | The byte data to add to the hash. |
finalizeFinalizes the hash computation and returns the result as a 32-byte array.func finalize() -> [UInt8] This is a non-consuming operation and can be called multiple times.
hexdigestReturns the current SHA-256 hash as a lowercase hexadecimal string.func hexdigest() -> String resetResets the hasher to its initial state.func reset()