axhash_core/hasher/
build.rs1use super::AxHasher;
2
3use crate::math::{DEFAULT_ACC, seed_lane};
4
5use core::hash::BuildHasher;
6
7#[derive(Clone, Copy)]
8pub struct AxBuildHasher {
9 pub(crate) prepared_seed: u64,
10}
11
12impl AxBuildHasher {
13 #[inline(always)]
14 pub const fn new() -> Self {
15 Self {
16 prepared_seed: DEFAULT_ACC,
17 }
18 }
19
20 #[inline(always)]
21 pub const fn with_seed(seed: u64) -> Self {
22 Self {
23 prepared_seed: seed_lane(seed, 0),
24 }
25 }
26
27 #[inline]
28 pub fn random() -> Self {
29 match getrandom::u64() {
30 Ok(seed) => Self::with_seed(seed),
31 Err(e) => panic!("failed to obtain random seed for AxBuildHasher: {e:?}"),
32 }
33 }
34}
35
36impl Default for AxBuildHasher {
37 #[inline(always)]
38 fn default() -> Self {
39 Self::new()
40 }
41}
42
43impl BuildHasher for AxBuildHasher {
44 type Hasher = AxHasher;
45
46 #[inline(always)]
47 fn build_hasher(&self) -> Self::Hasher {
48 AxHasher {
49 acc: self.prepared_seed,
50 sponge: 0,
51 sponge_bits: 0,
52 }
53 }
54}