Created
May 4, 2018 17:20
-
-
Save rjstelling/fc695f5c37beeefd2a810179b723b29f to your computer and use it in GitHub Desktop.
Data Extension for Fowler–Noll–Vo hash function
This file contains 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
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