#![allow(non_camel_case_types)]
use std::os::raw::c_void;
use ffi;
use hasher::FastHash;
pub struct Hash32;
impl FastHash for Hash32 {
type Hash = u32;
type Seed = u32;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u32) -> u32 {
unsafe {
ffi::MurmurHash2(
bytes.as_ref().as_ptr() as *const c_void,
bytes.as_ref().len() as i32,
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{murmur2::Hasher32, FastHasher};
let mut h = Hasher32::new();
h.write(b"hello");
assert_eq!(h.finish(), 3848350155);
h.write(b"world");
assert_eq!(h.finish(), 2155944146);
```
"#]
Hasher32,
Hash32
);
pub struct Hash32A;
impl FastHash for Hash32A {
type Hash = u32;
type Seed = u32;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u32) -> u32 {
unsafe {
ffi::MurmurHash2A(
bytes.as_ref().as_ptr() as *const c_void,
bytes.as_ref().len() as i32,
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{murmur2::Hasher32A, FastHasher};
let mut h = Hasher32A::new();
h.write(b"hello");
assert_eq!(h.finish(), 259931098);
h.write(b"world");
assert_eq!(h.finish(), 403945221);
```
"#]
Hasher32A,
Hash32A
);
pub struct Hash32Neutral;
impl FastHash for Hash32Neutral {
type Hash = u32;
type Seed = u32;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u32) -> u32 {
unsafe {
ffi::MurmurHashNeutral2(
bytes.as_ref().as_ptr() as *const c_void,
bytes.as_ref().len() as i32,
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{murmur2::Hasher32Neutral, FastHasher};
let mut h = Hasher32Neutral::new();
h.write(b"hello");
assert_eq!(h.finish(), 3848350155);
h.write(b"world");
assert_eq!(h.finish(), 2155944146);
```
"#]
Hasher32Neutral,
Hash32Neutral
);
pub struct Hash32Aligned;
impl FastHash for Hash32Aligned {
type Hash = u32;
type Seed = u32;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u32) -> u32 {
unsafe {
ffi::MurmurHashAligned2(
bytes.as_ref().as_ptr() as *const c_void,
bytes.as_ref().len() as i32,
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{murmur2::Hasher32Aligned, FastHasher};
let mut h = Hasher32Aligned::new();
h.write(b"hello");
assert_eq!(h.finish(), 3848350155);
h.write(b"world");
assert_eq!(h.finish(), 2155944146);
```
"#]
Hasher32Aligned,
Hash32Aligned
);
pub struct Hash64_x64;
impl FastHash for Hash64_x64 {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::MurmurHash64A(
bytes.as_ref().as_ptr() as *const c_void,
bytes.as_ref().len() as i32,
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{murmur2::Hasher64_x64, FastHasher};
let mut h = Hasher64_x64::new();
h.write(b"hello");
assert_eq!(h.finish(), 2191231550387646743);
h.write(b"world");
assert_eq!(h.finish(), 2139823713852166039);
```
"#]
Hasher64_x64,
Hash64_x64
);
pub struct Hash64_x86;
impl FastHash for Hash64_x86 {
type Hash = u64;
type Seed = u64;
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: u64) -> u64 {
unsafe {
ffi::MurmurHash64B(
bytes.as_ref().as_ptr() as *const c_void,
bytes.as_ref().len() as i32,
seed,
)
}
}
}
impl_hasher!(
#[doc = r#"
# Example
```
use std::hash::Hasher;
use fasthash::{murmur2::Hasher64_x86, FastHasher};
let mut h = Hasher64_x86::new();
h.write(b"hello");
assert_eq!(h.finish(), 17658855022785723775);
h.write(b"world");
assert_eq!(h.finish(), 14017254558097603378);
```
"#]
Hasher64_x86,
Hash64_x86
);
#[inline(always)]
pub fn hash32<T: AsRef<[u8]>>(v: T) -> u32 {
Hash32A::hash(v)
}
#[inline(always)]
pub fn hash32_with_seed<T: AsRef<[u8]>>(v: T, seed: u32) -> u32 {
Hash32A::hash_with_seed(v, seed)
}
#[inline(always)]
pub fn hash64<T: AsRef<[u8]>>(v: T) -> u64 {
if cfg!(target_pointer_width = "64") {
Hash64_x64::hash(v)
} else {
Hash64_x86::hash(v)
}
}
#[inline(always)]
pub fn hash64_with_seed<T: AsRef<[u8]>>(v: T, seed: u64) -> u64 {
if cfg!(target_pointer_width = "64") {
Hash64_x64::hash_with_seed(v, seed)
} else {
Hash64_x86::hash_with_seed(v, seed)
}
}