Skip to content
Draft
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 benches/throughput/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {

// GxHash
let gxhash_name = if cfg!(hybrid) { "gxhash-hybrid" } else { "gxhash" };
benchmark(processor.as_mut(), slice, gxhash_name, |data: &[u8], seed: i64| -> u64 {
benchmark(processor.as_mut(), slice, gxhash_name, |data: &[u8], seed: u64| -> u64 {
gxhash64(data, seed)
});

Expand Down
2 changes: 1 addition & 1 deletion benches/throughput_criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn benchmark_all(c: &mut Criterion) {
// GxHash
let gxhash_name = if cfg!(hybrid) { "gxhash-hybrid" } else { "gxhash" };
benchmark(&mut group, slice, gxhash_name, |data: &[u8], seed: i32| -> u64 {
gxhash64(data, seed as i64)
gxhash64(data, seed as u64)
});

// AHash
Expand Down
4 changes: 2 additions & 2 deletions ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use core::slice;

#[no_mangle]
pub unsafe extern "C" fn gxhash32(buf: *const (), len: usize, seed: i64) -> u32 {
pub unsafe extern "C" fn gxhash32(buf: *const (), len: usize, seed: u64) -> u32 {
let data: &[u8] = slice::from_raw_parts(buf as *const u8, len);
gxhash::gxhash32(data, seed)
}

#[no_mangle]
pub unsafe extern "C" fn gxhash64(buf: *const (), len: usize, seed: i64) -> u64 {
pub unsafe extern "C" fn gxhash64(buf: *const (), len: usize, seed: u64) -> u64 {
let data: &[u8] = slice::from_raw_parts(buf as *const u8, len);
gxhash::gxhash64(data, seed)
}
12 changes: 6 additions & 6 deletions src/gxhash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use platform::*;
/// println!("Hash is {:x}!", gxhash::gxhash32(&bytes, seed));
/// ```
#[inline(always)]
pub fn gxhash32(input: &[u8], seed: i64) -> u32 {
pub fn gxhash32(input: &[u8], seed: u64) -> u32 {
unsafe {
let p = &gxhash(input, create_seed(seed)) as *const State as *const u32;
*p
Expand All @@ -29,7 +29,7 @@ pub fn gxhash32(input: &[u8], seed: i64) -> u32 {
/// println!("Hash is {:x}!", gxhash::gxhash64(&bytes, seed));
/// ```
#[inline(always)]
pub fn gxhash64(input: &[u8], seed: i64) -> u64 {
pub fn gxhash64(input: &[u8], seed: u64) -> u64 {
unsafe {
let p = &gxhash(input, create_seed(seed)) as *const State as *const u64;
*p
Expand All @@ -46,7 +46,7 @@ pub fn gxhash64(input: &[u8], seed: i64) -> u64 {
/// println!("Hash is {:x}!", gxhash::gxhash128(&bytes, seed));
/// ```
#[inline(always)]
pub fn gxhash128(input: &[u8], seed: i64) -> u128 {
pub fn gxhash128(input: &[u8], seed: u64) -> u128 {
unsafe {
let p = &gxhash(input, create_seed(seed)) as *const State as *const u128;
*p
Expand Down Expand Up @@ -219,8 +219,8 @@ mod tests {
assert_eq!(4243413987, gxhash32(&[0u8; 1], 0));
assert_eq!(2401749549, gxhash32(&[0u8; 1000], 0));
assert_eq!(4156851105, gxhash32(&[42u8; 4242], 42));
assert_eq!(1981427771, gxhash32(&[42u8; 4242], -42));
assert_eq!(1156095992, gxhash32(b"Hello World", i64::MAX));
assert_eq!(540827083, gxhash32(b"Hello World", i64::MIN));
assert_eq!(1981427771, gxhash32(&[42u8; 4242], -42i64 as u64));
assert_eq!(1156095992, gxhash32(b"Hello World", i64::MAX as u64));
assert_eq!(540827083, gxhash32(b"Hello World", i64::MIN as u64));
}
}
4 changes: 2 additions & 2 deletions src/gxhash/platform/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub unsafe fn create_empty() -> State {
}

#[inline(always)]
pub unsafe fn create_seed(seed: i64) -> State {
vreinterpretq_s8_s64(vdupq_n_s64(seed))
pub unsafe fn create_seed(seed: u64) -> State {
vreinterpretq_s8_p64(vdupq_n_p64(seed))
}

#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions src/gxhash/platform/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub unsafe fn create_empty() -> State {
}

#[inline(always)]
pub unsafe fn create_seed(seed: i64) -> State {
_mm_set1_epi64x(seed)
pub unsafe fn create_seed(seed: u64) -> State {
_mm_set1_epi64x(seed as i64)
}

#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions src/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl GxHasher {
/// println!("Hash is {:x}!", hasher.finish());
/// ```
#[inline]
pub fn with_seed(seed: i64) -> GxHasher {
pub fn with_seed(seed: u64) -> GxHasher {
// Use gxhash64 to generate an initial state from a seed
GxHasher::with_state(unsafe { create_seed(seed) })
}
Expand Down Expand Up @@ -144,7 +144,7 @@ impl GxBuildHasher {
/// Hardcoding a seed may make your [`Hasher`] vulnerable to DOS attacks.
/// It is recommended to use [`GxBuildHasher::default()`] for improved DOS resistance.
#[inline]
pub fn with_seed(seed: i64) -> GxBuildHasher {
pub fn with_seed(seed: u64) -> GxBuildHasher {
// Use gxhash64 to generate an initial state from a seed
GxBuildHasher(unsafe { create_seed(seed) })
}
Expand Down