use core::hash::{BuildHasher, Hasher};
#[derive(Clone, Debug)]
pub struct RandomState(RandomStateImpl);
impl Default for RandomState {
#[inline]
fn default() -> RandomState {
RandomState(RandomStateImpl::default())
}
}
impl BuildHasher for RandomState {
type Hasher = RandomStateHasher;
#[inline]
fn build_hasher(&self) -> RandomStateHasher {
RandomStateHasher(self.0.build_hasher())
}
}
pub struct RandomStateHasher(<RandomStateImpl as BuildHasher>::Hasher);
impl Hasher for RandomStateHasher {
#[inline]
fn finish(&self) -> u64 {
self.0.finish()
}
#[inline]
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)
}
#[inline]
fn write_u8(&mut self, i: u8) {
self.0.write_u8(i)
}
#[inline]
fn write_u16(&mut self, i: u16) {
self.0.write_u16(i)
}
#[inline]
fn write_u32(&mut self, i: u32) {
self.0.write_u32(i)
}
#[inline]
fn write_u64(&mut self, i: u64) {
self.0.write_u64(i)
}
#[inline]
fn write_u128(&mut self, i: u128) {
self.0.write_u128(i)
}
#[inline]
fn write_usize(&mut self, i: usize) {
self.0.write_usize(i)
}
#[inline]
fn write_i8(&mut self, i: i8) {
self.0.write_i8(i)
}
#[inline]
fn write_i16(&mut self, i: i16) {
self.0.write_i16(i)
}
#[inline]
fn write_i32(&mut self, i: i32) {
self.0.write_i32(i)
}
#[inline]
fn write_i64(&mut self, i: i64) {
self.0.write_i64(i)
}
#[inline]
fn write_i128(&mut self, i: i128) {
self.0.write_i128(i)
}
#[inline]
fn write_isize(&mut self, i: isize) {
self.0.write_isize(i)
}
}
#[cfg(feature = "std")]
use std::collections::hash_map::RandomState as RandomStateImpl;
#[derive(Clone, Debug)]
#[cfg(not(feature = "std"))]
struct RandomStateImpl {
state: ahash::RandomState,
}
#[cfg(not(feature = "std"))]
impl Default for RandomStateImpl {
fn default() -> RandomStateImpl {
RandomStateImpl {
state: ahash::RandomState::new(),
}
}
}
#[cfg(not(feature = "std"))]
impl BuildHasher for RandomStateImpl {
type Hasher = ahash::AHasher;
#[inline]
fn build_hasher(&self) -> ahash::AHasher {
self.state.build_hasher()
}
}