MurmurHash framework in Swift.
A framework includes MurmurHash3's x86_32/x86_128/x64_128 functions.
- Platforms
- iOS 10.0+
- macOS 10.12+
- tvOS 12.0+
- Linux
- Swift 4.2, 5.0
use_frameworks!
target 'target' do
pod 'MurmurHash-Swift'
end
github "daisuke-t-jp/MurmurHash-Swift"
import MurmurHash_Swift
let digest = MurmurHash3.x86_32.digest("Hello World! Hello World!")
// digest -> 0x0be480fc
// Using seed.
let digest = MurmurHash3.x86_32.digest("Hello World! Hello World!", seed: 0x7fffffff)
// digest -> 0x47fcc800
let digest = MurmurHash3.x86_128.digestHex("Hello World! Hello World!")
// digest -> "86163d2b245b8ee23c4d056024166d77"
// Using seed.
let digest = MurmurHash3.x86_128.digestHex("Hello World! Hello World!", seed: 0x7fffffff)
// digest -> "d1ab28e6f4fc514c5e0df753b015261f"
let digest = MurmurHash3.x64_128.digestHex("Hello World! Hello World!")
// digest -> "e881a28e49269b1e8d0d724eecb72e66"
// Using seed.
let digest = MurmurHash3.x64_128.digestHex("Hello World! Hello World!", seed: 0x7fffffff)
// digest -> "6028586a8c3df476fbd535aec6551aab"
let mmh = MurmurHash3.x86_32() // if using seed, e.g. "MurmurHash3.x86_32(0x7fffffff)"
let bundle = Bundle(for: type(of: self))
let path = bundle.path(forResource: "alice29", ofType: "txt")!
let data = NSData(contentsOfFile: path)! as Data
let bufSize = 1024
var index = 0
repeat {
var lastIndex = index + bufSize
if lastIndex > data.count {
lastIndex = index + data.count - index
}
let data2 = data[index..<lastIndex]
mmh.update(data2)
index += data2.count
if index >= data.count {
break
}
} while(true)
let digest = mmh.digest()
// digest -> 0xcae14481
let mmh = MurmurHash3.x86_128() // if using seed, e.g. "MurmurHash3.x86_128(0x7fffffff)"
let bundle = Bundle(for: type(of: self))
let path = bundle.path(forResource: "alice29", ofType: "txt")!
let data = NSData(contentsOfFile: path)! as Data
let bufSize = 1024
var index = 0
repeat {
var lastIndex = index + bufSize
if lastIndex > data.count {
lastIndex = index + data.count - index
}
let data2 = data[index..<lastIndex]
mmh.update(data2)
index += data2.count
if index >= data.count {
break
}
} while(true)
let digest = mmh.digestHex()
// digest -> "f3d9739244076beaaaa983c7cc4c7251"
let mmh = MurmurHash3.x64_128() // if using seed, e.g. "MurmurHash3.x64_128(0x7fffffff)"
let bundle = Bundle(for: type(of: self))
let path = bundle.path(forResource: "alice29", ofType: "txt")!
let data = NSData(contentsOfFile: path)! as Data
let bufSize = 1024
var index = 0
repeat {
var lastIndex = index + bufSize
if lastIndex > data.count {
lastIndex = index + data.count - index
}
let data2 = data[index..<lastIndex]
mmh.update(data2)
index += data2.count
if index >= data.count {
break
}
} while(true)
let digest = mmh.digestHex()
// digest -> "ef12617f3e2a5f9a44b3598f2e09cd50"
There are demos.