Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ license = "MIT"

[dependencies]
cfg-if = { version = "0.1", default-features = false }
static_assertions = { version = "1.0", default-features = false }
static_assertions = { version = "1.1", default-features = false }
rand = { version = ">= 0.3.10, < 0.8", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true}
digest = { version = "0.9", default-features = false, optional = true }
Expand Down
16 changes: 8 additions & 8 deletions comparison/src/c_xxhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ mod ffi {
}

extern "C" {
pub fn XXH32(input: *const c_void, length: size_t, seed: u32) -> XXH32_hash_t;
pub fn XXH64(input: *const c_void, length: size_t, seed: u64) -> XXH64_hash_t;
pub fn XXH32(input: *const c_void, length: size_t, seed: XXH32_hash_t) -> XXH32_hash_t;
pub fn XXH64(input: *const c_void, length: size_t, seed: XXH64_hash_t) -> XXH64_hash_t;
pub fn XXH3_64bits_withSeed(
data: *const ::std::os::raw::c_void,
len: usize,
seed: ::std::os::raw::c_ulonglong,
data: *const c_void,
len: size_t,
seed: XXH64_hash_t,
) -> XXH64_hash_t;
pub fn XXH3_128bits_withSeed(
data: *const ::std::os::raw::c_void,
len: usize,
seed: ::std::os::raw::c_ulonglong,
data: *const c_void,
len: size_t,
seed: XXH64_hash_t,
) -> XXH128_hash_t;
}
}
Expand Down
71 changes: 70 additions & 1 deletion comparison/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use proptest::{collection::vec as propvec, prelude::*};
use std::hash::Hasher;
#[cfg(test)]
use twox_hash::{XxHash32, XxHash64};
use twox_hash::{xxh3, HasherExt, XxHash32, XxHash64};

pub mod c_xxhash;

Expand All @@ -12,6 +12,12 @@ pub fn hash_once(mut hasher: impl Hasher, data: &[u8]) -> u64 {
hasher.finish()
}

#[cfg(test)]
pub fn hash_once_ext(mut hasher: impl HasherExt, data: &[u8]) -> u128 {
hasher.write(&data);
hasher.finish_ext()
}

#[cfg(test)]
fn hash_by_chunks(mut hasher: impl Hasher, mut data: &[u8], chunk_sizes: &[usize]) -> u64 {
for &chunk_size in chunk_sizes {
Expand All @@ -23,6 +29,17 @@ fn hash_by_chunks(mut hasher: impl Hasher, mut data: &[u8], chunk_sizes: &[usize
hasher.finish()
}

#[cfg(test)]
fn hash_by_chunks_ext(mut hasher: impl HasherExt, mut data: &[u8], chunk_sizes: &[usize]) -> u128 {
for &chunk_size in chunk_sizes {
let (this_chunk, remaining) = data.split_at(chunk_size);
hasher.write(this_chunk);
data = remaining;
}

hasher.finish_ext()
}

prop_compose! {
fn data_and_offset
()
Expand Down Expand Up @@ -81,6 +98,41 @@ proptest! {

prop_assert_eq!(our_result, their_result as u64);
}

#[test]
fn same_results_as_c_for_xxh3_64_bit(seed: u64, data: Vec<u8>) {
let our_result = hash_once(xxh3::Hash64::with_seed(seed), &data);
let their_result = c_xxhash::xxh3_hash64(&data, seed);

prop_assert_eq!(our_result, their_result);
}

#[test]
fn same_results_as_c_with_offset_for_xxh3_64_bit(seed: u64, (data, offset) in data_and_offset()) {
let data = &data[offset..];
let our_result = hash_once(xxh3::Hash64::with_seed(seed), data);
let their_result = c_xxhash::xxh3_hash64(data, seed);

prop_assert_eq!(our_result, their_result);
}

#[test]
fn same_results_as_c_for_xxh3_128_bit(seed: u64, data: Vec<u8>) {
let our_result = hash_once_ext(xxh3::Hash128::with_seed(seed), &data);
let their_result = c_xxhash::xxh3_hash128(&data, seed);

prop_assert_eq!(our_result, their_result);
}

#[test]
fn same_results_as_c_with_offset_for_xxh3_128_bit(seed: u64, (data, offset) in data_and_offset()) {
let data = &data[offset..];
let our_result = hash_once_ext(xxh3::Hash128::with_seed(seed), data);
let their_result = c_xxhash::xxh3_hash128(data, seed);

prop_assert_eq!(our_result, their_result);
}

}

proptest! {
Expand All @@ -101,4 +153,21 @@ proptest! {

prop_assert_eq!(chunked_result, monolithic_result);
}

#[test]
fn same_results_with_many_chunks_as_one_for_xxh3_64_bit(seed: u64, (data, chunk_sizes) in data_and_chunk_sizes()) {
let chunked_result = hash_by_chunks(xxh3::Hash64::with_seed(seed), &data, &chunk_sizes);
let monolithic_result = hash_once(xxh3::Hash64::with_seed(seed), &data);

prop_assert_eq!(chunked_result, monolithic_result);
}

#[test]
fn same_results_with_many_chunks_as_one_for_xxh3_128_bit(seed: u64, (data, chunk_sizes) in data_and_chunk_sizes()) {
let chunked_result = hash_by_chunks_ext(xxh3::Hash128::with_seed(seed), &data, &chunk_sizes);
let monolithic_result = hash_once_ext(xxh3::Hash128::with_seed(seed), &data);

prop_assert_eq!(chunked_result, monolithic_result);
}

}
2 changes: 1 addition & 1 deletion comparison/xxHash
Submodule xxHash updated 52 files
+18 −5 .gitignore
+94 −42 .travis.yml
+52 −0 CHANGELOG
+25 −1 LICENSE
+221 −83 Makefile
+121 −87 README.md
+10 −7 appveyor.yml
+7 −7 cmake_unofficial/CMakeLists.txt
+4 −4 cmake_unofficial/README.md
+1 −1 doc/README.md
+206 −0 doc/xxhash.cry
+43 −42 doc/xxhash_spec.md
+15 −0 libxxhash.pc.in
+83 −0 tests/Makefile
+339 −0 tests/bench/LICENSE
+32 −3 tests/bench/Makefile
+21 −29 tests/bench/benchHash.c
+23 −30 tests/bench/benchHash.h
+14 −16 tests/bench/benchfn.c
+1 −1 tests/bench/benchfn.h
+21 −30 tests/bench/bhDisplay.c
+17 −26 tests/bench/bhDisplay.h
+24 −33 tests/bench/hashes.h
+60 −57 tests/bench/main.c
+1 −1 tests/bench/timefn.c
+1 −1 tests/bench/timefn.h
+2 −0 tests/collisions/.gitignore
+339 −0 tests/collisions/LICENSE
+74 −0 tests/collisions/Makefile
+122 −0 tests/collisions/README.md
+1 −0 tests/collisions/allcodecs/README.md
+38 −0 tests/collisions/allcodecs/dummy.c
+45 −0 tests/collisions/allcodecs/dummy.h
+127 −0 tests/collisions/hashes.h
+1,124 −0 tests/collisions/main.c
+344 −0 tests/collisions/pool.c
+80 −0 tests/collisions/pool.h
+59 −0 tests/collisions/sort.cc
+40 −0 tests/collisions/sort.hh
+82 −0 tests/collisions/threading.c
+124 −0 tests/collisions/threading.h
+154 −0 tests/generate_unicode_test.c
+66 −0 tests/multiInclude.c
+62 −0 tests/ppc_define.c
+49 −1,577 xxh3.h
+749 −0 xxh_x86dispatch.c
+86 −0 xxh_x86dispatch.h
+33 −1,108 xxhash.c
+4,538 −316 xxhash.h
+39 −24 xxhsum.1
+49 −25 xxhsum.1.md
+1,515 −671 xxhsum.c
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod digest_support;

pub use crate::sixty_four::XxHash64;
pub use crate::thirty_two::XxHash32;
pub use crate::xxh3::{Hash128 as Xxh3Hash128, Hash64 as Xxh3Hash64};
pub use crate::xxh3::{Hash128 as Xxh3Hash128, Hash64 as Xxh3Hash64, HasherExt};

/// A backwards compatibility type alias. Consider directly using
/// `XxHash64` instead.
Expand Down
Loading