4个版本
使用旧的Rust 2015
0.0.5 | 2015年8月12日 |
---|---|
0.0.4 | 2015年7月15日 |
0.0.2 | 2015年2月15日 |
0.0.0 | 2014年11月21日 |
1547 在 算法 中
6KB
84 行
SipHash.rs 
SipHash.rs 是SipHash哈希算法在Rust中的快速高效实现,但没有任何Rust运行时的依赖。
按设计,它只支持从内存中按顺序哈希字节。
由于它不依赖于Rust运行时,因此它可以用于独立的Rust程序,包括内核。
性能
在2.8GHz的Intel Xeon虚拟服务器上,它需要14ns(39周期)进行预热,然后大约每字节0.6ns(1.7周期)。
原始输出
test bench_for_size_00000 ... bench: 14 ns/iter (+/- 0)
test bench_for_size_00001 ... bench: 16 ns/iter (+/- 0)
test bench_for_size_00002 ... bench: 16 ns/iter (+/- 0)
test bench_for_size_00004 ... bench: 17 ns/iter (+/- 0)
test bench_for_size_00008 ... bench: 20 ns/iter (+/- 0)
test bench_for_size_00016 ... bench: 24 ns/iter (+/- 2)
test bench_for_size_00032 ... bench: 35 ns/iter (+/- 0)
test bench_for_size_00064 ... bench: 56 ns/iter (+/- 1)
test bench_for_size_00128 ... bench: 98 ns/iter (+/- 1)
test bench_for_size_00256 ... bench: 184 ns/iter (+/- 1)
test bench_for_size_00512 ... bench: 343 ns/iter (+/- 14)
test bench_for_size_01024 ... bench: 648 ns/iter (+/- 6)
test bench_for_size_02048 ... bench: 1277 ns/iter (+/- 16)
test bench_for_size_04096 ... bench: 2531 ns/iter (+/- 19)
test bench_for_size_65536 ... bench: 39718 ns/iter (+/- 1702)
您可以使用以下命令运行这些基准测试:make bench
。
使用方法
将siphash
作为依赖项添加到您的Cargo.toml
[package]
name = "foo"
version = "0.0.0"
authors = ["foo"]
[[bin]]
name = "foo"
[dependencies.siphash]
git = "https://github.com/utkarshkukreti/siphash.rs.git"
现在您可以在src/foo.rs
中添加siphash
作为extern crate
extern crate siphash;
fn main() {
let sip = siphash::SipHasher::new();
println!("hash for foo = {}", sip.hash(b"foo"));
}
现在构建并运行它
$ cargo build
Updating git repository `https://github.com/utkarshkukreti/siphash.rs.git`
Compiling siphash v0.0.0 (https://github.com/utkarshkukreti/siphash.rs.git)
Compiling foo v0.0.0 (file:/Users/utkarsh/dev/git/siphash.rs/examples)
$ target/foo
hash for foo = 15988776847138518036
许可证
SipHash作者提供的参考实现根据CC0许可证授权,这是一种类似公共领域的许可证。本库是它的直接移植,并且也根据CC0授权。