Skip to content

Instantly share code, notes, and snippets.

@morishin
Created January 5, 2020 08:23
Show Gist options
  • Save morishin/2270c532220cb2fbdc3ec5a7650c03f3 to your computer and use it in GitHub Desktop.
Save morishin/2270c532220cb2fbdc3ec5a7650c03f3 to your computer and use it in GitHub Desktop.
struct FNV1A {
static let FNVOffsetBasis: UInt = 14695981039346656037
static let FNVPrime: UInt = 1099511628211
static func digest(of source: String) -> UInt {
var hash = FNVOffsetBasis
for byte in [UInt8](source.utf8) {
hash ^= UInt(byte)
hash &*= FNVPrime
}
return hash
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment