use hasher::FastHash;
pub mod t1ha2 {
use hasher::FastHash;
pub struct Hash64AtOnce;
impl FastHash for Hash64AtOnce {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::t1ha2_atonce(
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{t1ha2::Hasher64, FastHasher};
let mut h = Hasher64::new();
h.write(b"hello");
assert_eq!(h.finish(), 3053206065578472372);
h.write(b"world");
assert_eq!(h.finish(), 15302361616348747620);
```
"#]
Hasher64,
Hash64AtOnce
);
pub struct Hash128AtOnce;
impl FastHash for Hash128AtOnce {
type Hash = u128;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u128 {
let mut hi = 0;
let lo = unsafe {
ffi::t1ha2_atonce128(
&mut hi,
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
};
u128::from(hi).wrapping_shl(64) + u128::from(lo)
}
}
impl_hasher_ext!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{t1ha2::Hasher128, FastHasher, HasherExt};
let mut h = Hasher128::new();
h.write(b"hello");
assert_eq!(h.finish_ext(), 181522150951767732353014146495581994137);
h.write(b"world");
assert_eq!(h.finish_ext(), 315212713565720527393405448145758944961);
```
"#]
Hasher128,
Hash128AtOnce
);
}
pub mod t1ha1 {
use hasher::FastHash;
cfg_if! {
if #[cfg(target_endian = "little")] {
pub use self::{Hasher64Le as Hasher64, Hash64Le as Hash64};
} else {
pub use self::{Hasher64Be as Hasher64, Hash64Be as Hash64};
}
}
pub struct Hash64Le;
impl FastHash for Hash64Le {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::t1ha1_le(
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{t1ha1::Hasher64Le, FastHasher};
let mut h = Hasher64Le::new();
h.write(b"hello");
assert_eq!(h.finish(), 12810198970222070563);
h.write(b"world");
assert_eq!(h.finish(), 16997942636322422782);
```
"#]
Hasher64Le,
Hash64Le
);
pub struct Hash64Be;
impl FastHash for Hash64Be {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::t1ha1_be(
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{t1ha1::Hasher64Be, FastHasher};
let mut h = Hasher64Be::new();
h.write(b"hello");
assert_eq!(h.finish(), 14880640220959195744);
h.write(b"world");
assert_eq!(h.finish(), 15825971635414726702);
```
"#]
Hasher64Be,
Hash64Be
);
}
pub mod t1ha0 {
use hasher::FastHash;
cfg_if! {
if #[cfg(any(feature = "avx2", target_feature = "avx2"))] {
pub use self::avx2::Hasher64 as Hasher64;
} else if #[cfg(any(feature = "avx", target_feature = "avx"))] {
pub use self::avx::Hasher64 as Hasher64;
} else if #[cfg(any(feature = "aes", target_feature = "aes"))] {
pub use self::aes::Hash64 as Hasher64;
} else {
pub use self::Hasher64_64 as Hasher64;
}
}
pub struct Hash64;
impl FastHash for Hash64 {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::t1ha0_64(
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{t1ha0::Hasher64, FastHasher};
let mut h = Hasher64::new();
h.write(b"hello");
assert_eq!(h.finish(), 3053206065578472372);
h.write(b"world");
assert_eq!(h.finish(), 15302361616348747620);
```
"#]
Hasher64_64,
Hash64
);
#[cfg(any(feature = "aes", target_feature = "aes"))]
pub mod aes {
use crate::FastHash;
pub struct Hash64;
impl FastHash for Hash64 {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::t1ha0_ia32aes_noavx(
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
}
}
}
impl_hasher!(Hasher64, Hash64);
}
#[cfg(any(feature = "avx", target_feature = "avx"))]
pub mod avx {
use crate::FastHash;
pub struct Hash64;
impl FastHash for Hash64 {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::t1ha0_ia32aes_avx(
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
}
}
}
impl_hasher!(Hasher64, Hash64);
}
#[cfg(any(feature = "avx2", target_feature = "avx2"))]
pub mod avx2 {
use crate::FastHash;
pub struct Hash64;
impl FastHash for Hash64 {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::t1ha0_ia32aes_avx2(
bytes.as_ref().as_ptr() as *const _,
bytes.as_ref().len(),
seed,
)
}
}
}
impl_hasher!(Hasher64, Hash64);
}
}
#[inline(always)]
pub fn hash64<T: AsRef<[u8]>>(v: T) -> u64 {
t1ha2::Hash64AtOnce::hash(v)
}
#[inline(always)]
pub fn hash64_with_seed<T: AsRef<[u8]>>(v: T, seed: u64) -> u64 {
t1ha2::Hash64AtOnce::hash_with_seed(v, seed)
}