Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
extern crate seahash;
use seahash::SeaHasher as H;
use std::hash::Hasher;
#[test]
fn hash_chunking_vs_not() {
// originally from https://gitlab.redox-os.org/redox-os/seahash/issues/5
let c1: &[u8] = b"This hashing algorithm was extracted from the Rustc compiler.";
let c2: &[u8] =
b" This is the same hashing algoirthm used for some internal operations in FireFox.";
let c3: &[u8] = b" The strength of this algorithm is in hashing 8 bytes at a time on 64-bit platforms, where the FNV algorithm works on one byte at a time.";
let mut h1 = H::default();
h1.write(c1);
h1.write(c2);
h1.write(c3);
let hash1 = h1.finish();
let mut c4 = Vec::<u8>::new();
c4.extend_from_slice(c1);
c4.extend_from_slice(c2);
c4.extend_from_slice(c3);
let mut h2 = H::default();
h2.write(&c4);
let hash2 = h2.finish();
let reference = seahash::reference::hash(&c4);
let buffer = seahash::hash(&c4);
println!("hash1: {:016x}", hash1);
println!("hash2: {:016x}", hash2);
println!("ref : {:016x}", reference);
println!("buf : {:016x}", buffer);
assert_eq!(hash1, hash2);
assert_eq!(hash1, reference);
assert_eq!(hash1, buffer);
assert_eq!(hash1, 0xa06e72e1b06144a0);
}
#[test]
fn test_different_chunk_sizes() {
let v = {
let c1: &[u8] = b"This hashing algorithm was extracted from the Rustc compiler.";
let c2: &[u8] =
b" This is the same hashing algoirthm used for some internal operations in FireFox.";
let c3: &[u8] = b" The strength of this algorithm is in hashing 8 bytes at a time on 64-bit platforms, where the FNV algorithm works on one byte at a time.";
[c1, c2, c3].concat()
};
let mut h1 = H::default();
h1.write(&v);
let h1 = h1.finish();
for chunk_len in 1..v.len() {
let mut h2 = H::default();
for w in v.chunks(chunk_len) {
h2.write(w);
}
let h2 = h2.finish();
assert_eq!(h1, h2, "failed with chunk_len={}", chunk_len);
}
}
+47
View File
@@ -0,0 +1,47 @@
extern crate seahash;
#[macro_use]
extern crate quickcheck;
use quickcheck::TestResult;
use seahash::hash;
use seahash::reference::hash as reference;
use seahash::SeaHasher;
use std::hash::Hasher;
use std::num::{NonZeroU8, NonZeroUsize};
quickcheck! {
#[cfg_attr(miri, ignore)] // very slow to run on miri
fn chunked_matches_buffered(xs: Vec<u8>, chunk_size: NonZeroUsize, times: NonZeroU8, additional: u8) -> TestResult {
let target_size = xs.len() * times.get() as usize + additional as usize;
if xs.is_empty() || target_size > 10_000_000 {
TestResult::discard()
} else {
let xs = xs.into_iter()
.cycle()
// the vecs produced by quickcheck are perhaps a bit small by default.
// additional should add some noise to avoid only getting nice even lengths.
.take(target_size)
.collect::<Vec<_>>();
// write all at once
let mut h0 = SeaHasher::default();
h0.write(&xs);
let h0 = h0.finish();
// write in chunks
let mut h1 = SeaHasher::default();
for chunk in xs.chunks(chunk_size.get()) {
h1.write(chunk);
}
let h1 = h1.finish();
// compare all, including to buffered and reference
let outcome = h0 == h1
&& h0 == hash(&xs)
&& h0 == reference(&xs);
TestResult::from_bool(outcome)
}
}
}