xxHash
xxHash C library
Swift Clinic for包装
- xxHash32
- xxHash64
- xxHash3 64位 (类 xxHash3)
- xxHash3 128位 (类 xxHash128)
入门
安装
Package Manager
将以下依赖项添加到您的 Package.swift
.package(url: "https://github.com/tesseract-one/xxHash.swift.git", from: "0.1.0")
运行 swift build
并构建您的应用。
CocoaPods
将以下内容添加到您的 Podfile
pod 'xxHash', '~> 0.1.0'
然后运行 pod install
示例
一次性方法
import xxHash
let hash64 = xxHash64.hash("UTF8 string")
let hash32 = xxHash32.hash([1, 255, 127, 0], seed: 1234)
let hash3_64 = xxHash3.hash(Data())
let hash3_128 = xxHash128.hash(Data(), seed: 1234, secret: Data(repeating: 0xff, count: 32))
流式API
import xxHash
var hasher = try xxHash64(seed: 1234) // or xxHash64() for empty seed
try hasher.update("Some string") // string
try hasher.update([1, 2, 255, 127]) // byte array
try hasher.update(Data(repeating: 0xff, count: 32)) // data
let hash = hasher.digest()
助手方法
import xxHash
// Canonical form of hash (BE bytes array)
let intHash = xxHash64.hash("UTF8 string")
let hashBytes = xxHash64.canonical(hash: intHash)
let restored = try xxHash64.hash(canonical: hashBytes)
assert(intHash == restored)
// Secret generation for xxHash3
let secret1 = xxHash3.generateSecret(seed: 12345678) // from UInt64
let secret2 = try xxHash3.generateSecret(seed: Data(repeating: 0xff, count: 32)) // from seed data
let secret3 = try xxHash3.generateSecret(seed: "Some string") // from seed string
let secret4 = try xxHash3.generateSecret(seed: [1, 255, 254, 127]) // from byte array
作者
许可证
xxHash.swift 在Apache 2.0许可证下可用。更多信息请参阅LICENSE文件。