Created
January 5, 2020 08:23
-
-
Save morishin/2270c532220cb2fbdc3ec5a7650c03f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash