diff --git a/Sources/CRC/CRC32.swift b/Sources/CRC/CRC32.swift index a651855..b207fb5 100644 --- a/Sources/CRC/CRC32.swift +++ b/Sources/CRC/CRC32.swift @@ -1,8 +1,10 @@ import Base16 +/// The value of a [CRC32](https://en.wikipedia.org/wiki/Cyclic_redundancy_check) checksum. @frozen public struct CRC32:Hashable, Sendable { + @_documentation(visibility: internal) public static let table:[UInt32] = (0 ..< 256).map { @@ -10,30 +12,37 @@ struct CRC32:Hashable, Sendable (0 ..< 8).reduce(i){ (c, _) in (c & 1 * 0xed_b8_83_20) ^ c >> 1 } } + /// The checksum value as a 32-bit unsigned integer. public var checksum:UInt32 + /// Creates a new checksum with the specified value. @inlinable public init(checksum:UInt32 = 0) { self.checksum = checksum } + + /// Computes the checksum of the provided message. @inlinable public - init(hashing message:some Sequence) + init(hashing message:borrowing some Sequence) { self.init() self.update(with: message) } + /// Returns a new checksum by hashing the provided message into the current checksum. @inlinable public - func updated(with message:some Sequence) -> Self + func updated(with message:borrowing some Sequence) -> Self { var checksum:Self = self checksum.update(with: message) return checksum } + + /// Updates the checksum by hashing the provided message into the existing checksum. @inlinable public mutating - func update(with message:some Sequence) + func update(with message:borrowing some Sequence) { self.checksum = ~message.reduce(~self.checksum) { @@ -52,6 +61,7 @@ extension CRC32:ExpressibleByIntegerLiteral } extension CRC32:CustomStringConvertible { + /// The lowercased hexadecimal representation of the checksum value. @inlinable public var description:String {