Skip to content

Commit

Permalink
Add crc32fast
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Sep 15, 2023
1 parent cd867f7 commit 2e7ad95
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions experimental/hashcmp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ t1ha = "0.1.0"
wyhash = "0.5.0"
twox-hash = "1.6.3"
xxhash-rust = { version = "0.8.7", features = ["xxh64", "xxh32", "xxh3"] }
crc32fast = "1.3"

[dev-dependencies]
55 changes: 55 additions & 0 deletions experimental/hashcmp/src/bin/crc32fast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#![no_main] // https://github.com/unicode-org/icu4x/issues/395

use std::hash::Hasher;
use std::collections::BTreeSet;

const ALPHANUMS: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";

#[no_mangle]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let seed = std::hint::black_box(2023u32);
let mut hashes = BTreeSet::new();
let mut hashes_32bit = BTreeSet::new();
let mut record = |hashed| {
hashes.insert(hashed);
hashes_32bit.insert(hashed as u32);
};
let mut cases = 0;
for i in 0u8..255 {
let mut hasher = crc32fast::Hasher::new_with_initial(seed);
hasher.write_u8(i);
record(hasher.finish());
cases += 1;
}
for a in ALPHANUMS.iter() {
for b in ALPHANUMS.iter() {
for c in ALPHANUMS.iter() {
let mut hasher = crc32fast::Hasher::new_with_initial(seed);
hasher.write_u8(*a);
hasher.write_u8(*b);
hasher.write_u8(*c);
record(hasher.finish());
cases += 1;
}
}
}
for start in 0..63 {
for stride in 1..=63 {
for count in 4..=63 {
let mut hasher = crc32fast::Hasher::new_with_initial(seed);
for i in 0..count {
let j = (start + i*stride) % 63;
hasher.write_u8(ALPHANUMS[j]);
}
record(hasher.finish());
cases += 1;
}
}
}
println!("unique hashes: {} / {} (32-bit: {})", hashes.len(), cases, hashes_32bit.len());
0
}

0 comments on commit 2e7ad95

Please sign in to comment.