| 1 |
use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::{BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#}; |
| 2 |
use siphasherrust-analyzer cargo siphasher 1.0.1 crate/::siprust-analyzer cargo siphasher 1.0.1 sip/::SipHasher13rust-analyzer cargo siphasher 1.0.1 sip/SipHasher13#; |
| 3 |
|
| 4 |
#[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 5 |
#[cfg_attr(feature = "serde", derive(serderust-analyzer cargo serde 1.0.210 crate/::Serializerust-analyzer cargo serde_derive 1.0.210 Serialize:, serderust-analyzer cargo serde 1.0.210 crate/::Deserializerust-analyzer cargo serde_derive 1.0.210 Deserialize:))] |
| 6 |
pub struct CloneBuildHasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> { |
| 7 |
hasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#hasher.: H, |
| 8 |
} |
| 9 |
|
| 10 |
impl<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> CloneBuildHasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#<H> { |
| 11 |
#[allow(dead_code)] |
| 12 |
fn newrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<H>`]new().(hasher: H) -> Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<H>`] { |
| 13 |
Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<H>`] { hasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#hasher. } |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
impl<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# for CloneBuildHasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#<H> { |
| 18 |
type Hasherrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<H>`][BuildHasher]Hasher# = H; |
| 19 |
#[inline] |
| 20 |
fn build_hasherrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<H>`][BuildHasher]build_hasher().(&self) -> Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<H>`][BuildHasher]::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#Hasher# { |
| 21 |
self.hasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#hasher..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
/// The default hasher for `BloomFilter`. |
| 26 |
/// |
| 27 |
/// `DefaultHasher` has a faster `build_hasher` than `std::collections::hash_map::RandomState` or `SipHasher13`. |
| 28 |
/// This is important because `build_hasher` is called once for every actual hash. |
| 29 |
pub type DefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/DefaultHasher# = CloneBuildHasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#<RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#>; |
| 30 |
|
| 31 |
impl DefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/DefaultHasher# { |
| 32 |
pub fn seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<RandomDefaultHasher>`]seeded().(seed: &[u8; 16]) -> Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<RandomDefaultHasher>`] { |
| 33 |
Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[`CloneBuildHasher<RandomDefaultHasher>`] { |
| 34 |
hasherrust-analyzer cargo fastbloom 0.17.0 hasher/CloneBuildHasher#hasher.: RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(seed), |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
#[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 40 |
#[cfg_attr(feature = "serde", derive(serderust-analyzer cargo serde 1.0.210 crate/::Serializerust-analyzer cargo serde_derive 1.0.210 Serialize:, serderust-analyzer cargo serde 1.0.210 crate/::Deserializerust-analyzer cargo serde_derive 1.0.210 Deserialize:))] |
| 41 |
pub struct RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#(SipHasher13rust-analyzer cargo siphasher 1.0.1 sip/SipHasher13#); |
| 42 |
|
| 43 |
impl RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher# { |
| 44 |
#[inline] |
| 45 |
pub fn seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(seed: &[u8; 16]) -> Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher] { |
| 46 |
Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher](SipHasher13rust-analyzer cargo siphasher 1.0.1 sip/SipHasher13#::new_with_keyrust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13]new_with_key().(seed)) |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher# { |
| 51 |
#[inline] |
| 52 |
fn defaultrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Default]default().() -> Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Default] { |
| 53 |
#[cfg(not(feature = "rand"))] |
| 54 |
{ |
| 55 |
use foldhashrust-analyzer cargo foldhash 0.2.0 crate/::fastrust-analyzer cargo foldhash 0.2.0 fast/::RandomStaterust-analyzer cargo foldhash 0.2.0 fast/RandomState#; |
| 56 |
|
| 57 |
// create two random states |
| 58 |
let state_a = RandomState::default(); |
| 59 |
let state_b = RandomState::default(); |
| 60 |
|
| 61 |
// combine the two random states into a single 128-bit seed |
| 62 |
let low = state_a.build_hasher().finish() as u128; |
| 63 |
let high = state_b.build_hasher().finish() as u128; |
| 64 |
|
| 65 |
Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Default]::seeded(&((high << 64) | low).to_ne_bytes()) |
| 66 |
} |
| 67 |
#[cfg(feature = "rand")] |
| 68 |
{ |
| 69 |
let mut seed = [0u8; 16]; |
| •70 |
use randrust-analyzer cargo rand 0.10.2 crate/::Rngrust-analyzer cargo rand_core 0.10.1 Rng#; |
| 71 |
randrust-analyzer cargo rand 0.10.2 crate/::rngrust-analyzer cargo rand 0.10.2 rngs/thread/rng().().fill_bytesrust-analyzer cargo rand_core 0.10.1 impl#[R][Rng]fill_bytes().(&mut seed); |
| 72 |
Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Default]::seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(&seed) |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
impl Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher# for RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher# { |
| 78 |
#[inline] |
| 79 |
fn finishrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]finish().(&self) -> u64 { |
| 80 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..finishrust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13][Hasher]finish().() |
| 81 |
} |
| 82 |
#[inline] |
| 83 |
fn writerust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write().(&mut self, bytes: &[u8]) { |
| 84 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..writerust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13][Hasher]write().(bytes) |
| 85 |
} |
| 86 |
#[inline] |
| 87 |
fn write_u8rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_u8().(&mut self, i: u8) { |
| 88 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_u8rust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13][Hasher]write_u8().(i) |
| 89 |
} |
| 90 |
#[inline] |
| 91 |
fn write_u16rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_u16().(&mut self, i: u16) { |
| 92 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_u16rust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13][Hasher]write_u16().(i) |
| 93 |
} |
| 94 |
#[inline] |
| 95 |
fn write_u32rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_u32().(&mut self, i: u32) { |
| 96 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_u32rust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13][Hasher]write_u32().(i) |
| 97 |
} |
| 98 |
#[inline] |
| 99 |
fn write_u64rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_u64().(&mut self, i: u64) { |
| 100 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_u64rust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13][Hasher]write_u64().(i) |
| 101 |
} |
| 102 |
#[inline] |
| 103 |
fn write_u128rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_u128().(&mut self, i: u128) { |
| 104 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_u128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u128().(i) |
| 105 |
} |
| 106 |
#[inline] |
| 107 |
fn write_usizerust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_usize().(&mut self, i: usize) { |
| 108 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_usizerust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13][Hasher]write_usize().(i) |
| 109 |
} |
| 110 |
#[inline] |
| 111 |
fn write_i8rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_i8().(&mut self, i: i8) { |
| 112 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_i8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i8().(i) |
| 113 |
} |
| 114 |
#[inline] |
| 115 |
fn write_i16rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_i16().(&mut self, i: i16) { |
| 116 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_i16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i16().(i) |
| 117 |
} |
| 118 |
#[inline] |
| 119 |
fn write_i32rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_i32().(&mut self, i: i32) { |
| 120 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_i32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i32().(i) |
| 121 |
} |
| 122 |
#[inline] |
| 123 |
fn write_i64rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_i64().(&mut self, i: i64) { |
| 124 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_i64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i64().(i) |
| 125 |
} |
| 126 |
#[inline] |
| 127 |
fn write_i128rust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_i128().(&mut self, i: i128) { |
| 128 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_i128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i128().(i) |
| 129 |
} |
| 130 |
#[inline] |
| 131 |
fn write_isizerust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]write_isize().(&mut self, i: isize) { |
| 132 |
self.0rust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#0..write_isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_isize().(i) |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
#[cfg(test)] |
| 137 |
mod testrust-analyzer cargo fastbloom 0.17.0 hasher/test/ { |
| 138 |
use craterust-analyzer cargo fastbloom 0.17.0 crate/::hasherrust-analyzer cargo fastbloom 0.17.0 hasher/::RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#; |
| 139 |
use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#; |
| 140 |
use siphasherrust-analyzer cargo siphasher 1.0.1 crate/::siprust-analyzer cargo siphasher 1.0.1 sip/::SipHasher13rust-analyzer cargo siphasher 1.0.1 sip/SipHasher13#; |
| 141 |
|
| 142 |
fn hash_allrust-analyzer cargo fastbloom 0.17.0 hasher/test/hash_all().(mut x: impl Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#) -> u64 { |
| 143 |
x.writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write().(&[1; 16]); |
| 144 |
x.write_u8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u8().(1); |
| 145 |
x.write_u16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u16().(1); |
| 146 |
x.write_u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u32().(1); |
| 147 |
x.write_u64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u64().(1); |
| 148 |
x.write_u128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u128().(1); |
| 149 |
x.write_usizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_usize().(1); |
| 150 |
x.write_i8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i8().(1); |
| 151 |
x.write_i16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i16().(1); |
| 152 |
x.write_i32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i32().(1); |
| 153 |
x.write_i64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i64().(1); |
| 154 |
x.write_i128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_i128().(1); |
| 155 |
x.write_isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_isize().(1); |
| 156 |
x.finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#finish().() |
| 157 |
} |
| 158 |
|
| 159 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 160 |
fn test_hasherrust-analyzer cargo fastbloom 0.17.0 hasher/test/test_hasher().() { |
| 161 |
let h1 = RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(&[0; 16]); |
| 162 |
let h2 = SipHasher13rust-analyzer cargo siphasher 1.0.1 sip/SipHasher13#::new_with_keyrust-analyzer cargo siphasher 1.0.1 sip/impl#[SipHasher13]new_with_key().(&[0; 16]); |
| 163 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hash_allrust-analyzer cargo fastbloom 0.17.0 hasher/test/hash_all().(h1), hash_allrust-analyzer cargo fastbloom 0.17.0 hasher/test/hash_all().(h2),); |
| 164 |
} |
| 165 |
|
| 166 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 167 |
fn test_random_default_hasherrust-analyzer cargo fastbloom 0.17.0 hasher/test/test_random_default_hasher().() { |
| 168 |
// two different instances of RandomDefaultHasher should have different seeds |
| 169 |
let h1 = RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::defaultrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Default]default().(); |
| 170 |
let h2 = RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::defaultrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Default]default().(); |
| 171 |
assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(h1.finishrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]finish().(), h2.finishrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]finish().()); |
| 172 |
|
| 173 |
// same seed value should result in the same hash |
| 174 |
let h3 = RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(&[0; 16]); |
| 175 |
let h4 = RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(&[0; 16]); |
| 176 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(h3.finishrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]finish().(), h4.finishrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]finish().()); |
| 177 |
|
| 178 |
// different seed value should result in different hash |
| 179 |
let h5 = RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(&[1; 16]); |
| 180 |
let h6 = RandomDefaultHasherrust-analyzer cargo fastbloom 0.17.0 hasher/RandomDefaultHasher#::seededrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher]seeded().(&[2; 16]); |
| 181 |
assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(h5.finishrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]finish().(), h6.finishrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[RandomDefaultHasher][Hasher]finish().()); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
#[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 186 |
pub(craterust-analyzer cargo fastbloom 0.17.0 crate/) struct DoubleHasherrust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher# { |
| 187 |
h1rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h1.: u64, |
| 188 |
h2rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h2.: u64, |
| 189 |
} |
| 190 |
|
| 191 |
impl DoubleHasherrust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher# { |
| 192 |
/// The first two hashes of the value, h1 and h2. |
| 193 |
/// |
| 194 |
/// Subsequent hashes, h, are efficiently derived from these two using `next_hash`. |
| 195 |
/// |
| 196 |
/// This strategy is a modified version of <https://www.eecs.harvard.edu/~michaelm/postscripts/rsa2008.pdf>. |
| 197 |
#[inline] |
| 198 |
pub(craterust-analyzer cargo fastbloom 0.17.0 crate/) fn newrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[DoubleHasher]new().(h1: u64) -> Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[DoubleHasher] { |
| 199 |
// 0xffff_ffff_ffff_ffff / 0x517c_c1b7_2722_0a95 = π |
| 200 |
let h2 = h1.wrapping_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_mul().(0x51_7c_c1_b7_27_22_0a_95); |
| 201 |
Selfrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[DoubleHasher] { h1rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h1., h2rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h2. } |
| 202 |
} |
| 203 |
|
| 204 |
/// "Double hashing" produces a new hash efficiently from two orignal hashes. |
| 205 |
/// |
| 206 |
/// Modified from <https://www.eecs.harvard.edu/~michaelm/postscripts/rsa2008.pdf>. |
| 207 |
#[inline] |
| 208 |
pub(craterust-analyzer cargo fastbloom 0.17.0 crate/) fn nextrust-analyzer cargo fastbloom 0.17.0 hasher/impl#[DoubleHasher]next().(&mut self) -> u64 { |
| 209 |
self.h1rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h1. = self.h1rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h1..rotate_leftrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]rotate_left().(5).wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_add().(self.h2rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h2.); |
| 210 |
self.h1rust-analyzer cargo fastbloom 0.17.0 hasher/DoubleHasher#h1. |
| 211 |
} |
| 212 |
} |