Skip to content

Instantly share code, notes, and snippets.

@rjstelling
Created May 4, 2018 17:20
Show Gist options
  • Save rjstelling/fc695f5c37beeefd2a810179b723b29f to your computer and use it in GitHub Desktop.
Save rjstelling/fc695f5c37beeefd2a810179b723b29f to your computer and use it in GitHub Desktop.
Data Extension for Fowler–Noll–Vo hash function
import Foundation
extension Data {
public var fnv32Hash: UInt32 {
return UInt32( self.reduce(0x811c9dc5) { 0x00000000FFFFFFFF & ($0 * 16777619) ^ UInt64($1) } )
}
public func fnv32HashString() -> String {
return String(format: "%08x", self.fnv32Hash)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment