summaryrefslogtreecommitdiffstats
path: root/vendor/ahash
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ahash')
-rw-r--r--vendor/ahash/.cargo-checksum.json2
-rw-r--r--vendor/ahash/Cargo.toml13
-rw-r--r--vendor/ahash/src/aes_hash.rs41
-rw-r--r--vendor/ahash/src/convert.rs7
-rw-r--r--vendor/ahash/src/hash_quality_test.rs44
-rw-r--r--vendor/ahash/src/operations.rs35
6 files changed, 85 insertions, 57 deletions
diff --git a/vendor/ahash/.cargo-checksum.json b/vendor/ahash/.cargo-checksum.json
index 305ffa617..72100165a 100644
--- a/vendor/ahash/.cargo-checksum.json
+++ b/vendor/ahash/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"136a7b1e64c2da6e4b948e9bb7d2429453b7a89cffc3828b9a81584716d22e2f","FAQ.md":"9eb41898523ee209a0a937f9bcb78afe45ad55ca0556f8a4d4063558098f6d1e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0444c6991eead6822f7b9102e654448d51624431119546492e8b231db42c48bb","README.md":"40d63866ffeabb0ae8fd65715f1da447ace146379ecc5c11fc61a84995edeaff","build.rs":"21e62c29f64f294a6871b5f0831b789cadc5f8e4e02423ab9acccb30c4d401bd","rustfmt.toml":"e090969e99df9360705680cc0097cfaddae10c22dc2e01470592cf3b9787fd36","src/aes_hash.rs":"1392355b354446bd71d9bfcf654b8209210974268db658f8f30c10594b7e421f","src/convert.rs":"b47fc60fc47b3492235da337d4ba247bd80a3e0b5e468d34784db24f1f294244","src/fallback_hash.rs":"37cb76793cd11f0b582e89c91ffaeb7270ed31c90b3a3c082a87ccbe9b188fcc","src/hash_map.rs":"5ee97baa64fa528ba9c01bd018332c4974846c4813c6f8c30cee9f3546598f1c","src/hash_quality_test.rs":"4396264603d0739f1464b191019f4c7c5b2ffe511ca375bc63de3e6a3a113958","src/hash_set.rs":"360e55d066b44624f06e49efa140c03fda635fb17a59622cc29a83830bd1f263","src/lib.rs":"940ab09005f8e98b01ad40da35b69e0fb2de998d58960ed501d24568f3d9f363","src/operations.rs":"605b0bfadf8d4abb4416c33a056cfefc694f6de60591a8fd39bb5a12e91a3286","src/random_state.rs":"fefae5d124933163abf69471589758870ab4e387a2142c7d94f545de9b1f6b20","src/specialize.rs":"56354db8a0f7e6ee1340a08f2ab6f79a0ff439fd61badac5e7e59fe4f4a653ba","tests/bench.rs":"6455dedf9db9fb03b2ea4a5a4b9efbeeee3ac3019c66d68dcb0560e3e58ff8e3","tests/map_tests.rs":"6161e7255fc22977ad871d8bcf948717a8b57b503033d9ddb565f3b145ccab34","tests/nopanic.rs":"0d28a46248d77283941db1d9fd154c68b965c81a0e3db1fe4a43e06fc448da8f"},"package":"2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"} \ No newline at end of file
+{"files":{"Cargo.toml":"a05cb9b3c018f30fed8e55601dd0fb838b56b36116f56d743ae38d064c62fb95","FAQ.md":"9eb41898523ee209a0a937f9bcb78afe45ad55ca0556f8a4d4063558098f6d1e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0444c6991eead6822f7b9102e654448d51624431119546492e8b231db42c48bb","README.md":"40d63866ffeabb0ae8fd65715f1da447ace146379ecc5c11fc61a84995edeaff","build.rs":"21e62c29f64f294a6871b5f0831b789cadc5f8e4e02423ab9acccb30c4d401bd","rustfmt.toml":"e090969e99df9360705680cc0097cfaddae10c22dc2e01470592cf3b9787fd36","src/aes_hash.rs":"96eb957af18f7b0d42561bf5f391bb79154785bf3a43e7ac21bd1f7f0017b209","src/convert.rs":"54e49f93d51665366923d4d815cfd67790d3c769e84ab4386ba97f928d17d1bd","src/fallback_hash.rs":"37cb76793cd11f0b582e89c91ffaeb7270ed31c90b3a3c082a87ccbe9b188fcc","src/hash_map.rs":"5ee97baa64fa528ba9c01bd018332c4974846c4813c6f8c30cee9f3546598f1c","src/hash_quality_test.rs":"b96a36f2ccd7332489bccfe3130b08caea86fa1f852e221fe97858940d329f05","src/hash_set.rs":"360e55d066b44624f06e49efa140c03fda635fb17a59622cc29a83830bd1f263","src/lib.rs":"940ab09005f8e98b01ad40da35b69e0fb2de998d58960ed501d24568f3d9f363","src/operations.rs":"1318731c6dfd245cc04a982ad9f438decf8b87b2194f4725ef01f211fe9ab377","src/random_state.rs":"fefae5d124933163abf69471589758870ab4e387a2142c7d94f545de9b1f6b20","src/specialize.rs":"56354db8a0f7e6ee1340a08f2ab6f79a0ff439fd61badac5e7e59fe4f4a653ba","tests/bench.rs":"6455dedf9db9fb03b2ea4a5a4b9efbeeee3ac3019c66d68dcb0560e3e58ff8e3","tests/map_tests.rs":"6161e7255fc22977ad871d8bcf948717a8b57b503033d9ddb565f3b145ccab34","tests/nopanic.rs":"0d28a46248d77283941db1d9fd154c68b965c81a0e3db1fe4a43e06fc448da8f"},"package":"91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"} \ No newline at end of file
diff --git a/vendor/ahash/Cargo.toml b/vendor/ahash/Cargo.toml
index a027c55a5..934051dfb 100644
--- a/vendor/ahash/Cargo.toml
+++ b/vendor/ahash/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "ahash"
-version = "0.8.3"
+version = "0.8.6"
authors = ["Tom Kaitchuck <Tom.Kaitchuck@gmail.com>"]
build = "./build.rs"
exclude = [
@@ -38,6 +38,7 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/tkaitchuck/ahash"
[package.metadata.docs.rs]
+features = ["std"]
rustc-args = [
"-C",
"target-feature=+aes",
@@ -46,20 +47,19 @@ rustdoc-args = [
"-C",
"target-feature=+aes",
]
-features = ["std"]
[profile.bench]
opt-level = 3
lto = "fat"
codegen-units = 1
-debug = false
+debug = 0
debug-assertions = false
[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
-debug = false
+debug = 0
debug-assertions = false
[profile.test]
@@ -103,6 +103,11 @@ optional = true
version = "1.0.117"
optional = true
+[dependencies.zerocopy]
+version = "0.7.14"
+features = ["simd"]
+default-features = false
+
[dev-dependencies.criterion]
version = "0.3.2"
features = ["html_reports"]
diff --git a/vendor/ahash/src/aes_hash.rs b/vendor/ahash/src/aes_hash.rs
index 702044e5e..0b9a1d4cf 100644
--- a/vendor/ahash/src/aes_hash.rs
+++ b/vendor/ahash/src/aes_hash.rs
@@ -81,23 +81,23 @@ impl AHasher {
#[inline(always)]
fn hash_in(&mut self, new_value: u128) {
- self.enc = aesenc(self.enc, new_value);
+ self.enc = aesdec(self.enc, new_value);
self.sum = shuffle_and_add(self.sum, new_value);
}
#[inline(always)]
fn hash_in_2(&mut self, v1: u128, v2: u128) {
- self.enc = aesenc(self.enc, v1);
+ self.enc = aesdec(self.enc, v1);
self.sum = shuffle_and_add(self.sum, v1);
- self.enc = aesenc(self.enc, v2);
+ self.enc = aesdec(self.enc, v2);
self.sum = shuffle_and_add(self.sum, v2);
}
#[inline]
#[cfg(feature = "specialize")]
fn short_finish(&self) -> u64 {
- let combined = aesdec(self.sum, self.enc);
- let result: [u64; 2] = aesenc(combined, combined).convert();
+ let combined = aesenc(self.sum, self.enc);
+ let result: [u64; 2] = aesdec(combined, combined).convert();
result[0]
}
}
@@ -164,28 +164,29 @@ impl Hasher for AHasher {
let tail = data.read_last_u128x4();
let mut current: [u128; 4] = [self.key; 4];
current[0] = aesenc(current[0], tail[0]);
- current[1] = aesenc(current[1], tail[1]);
+ current[1] = aesdec(current[1], tail[1]);
current[2] = aesenc(current[2], tail[2]);
- current[3] = aesenc(current[3], tail[3]);
- let mut sum: [u128; 2] = [self.key, self.key];
+ current[3] = aesdec(current[3], tail[3]);
+ let mut sum: [u128; 2] = [self.key, !self.key];
sum[0] = add_by_64s(sum[0].convert(), tail[0].convert()).convert();
sum[1] = add_by_64s(sum[1].convert(), tail[1].convert()).convert();
sum[0] = shuffle_and_add(sum[0], tail[2]);
sum[1] = shuffle_and_add(sum[1], tail[3]);
while data.len() > 64 {
let (blocks, rest) = data.read_u128x4();
- current[0] = aesenc(current[0], blocks[0]);
- current[1] = aesenc(current[1], blocks[1]);
- current[2] = aesenc(current[2], blocks[2]);
- current[3] = aesenc(current[3], blocks[3]);
+ current[0] = aesdec(current[0], blocks[0]);
+ current[1] = aesdec(current[1], blocks[1]);
+ current[2] = aesdec(current[2], blocks[2]);
+ current[3] = aesdec(current[3], blocks[3]);
sum[0] = shuffle_and_add(sum[0], blocks[0]);
sum[1] = shuffle_and_add(sum[1], blocks[1]);
sum[0] = shuffle_and_add(sum[0], blocks[2]);
sum[1] = shuffle_and_add(sum[1], blocks[3]);
data = rest;
}
- self.hash_in_2(aesenc(current[0], current[1]), aesenc(current[2], current[3]));
- self.hash_in(add_by_64s(sum[0].convert(), sum[1].convert()).convert());
+ self.hash_in_2(current[0], current[1]);
+ self.hash_in_2(current[2], current[3]);
+ self.hash_in_2(sum[0], sum[1]);
} else {
//len 33-64
let (head, _) = data.read_u128x2();
@@ -207,8 +208,8 @@ impl Hasher for AHasher {
}
#[inline]
fn finish(&self) -> u64 {
- let combined = aesdec(self.sum, self.enc);
- let result: [u64; 2] = aesenc(aesenc(combined, self.key), combined).convert();
+ let combined = aesenc(self.sum, self.enc);
+ let result: [u64; 2] = aesdec(aesdec(combined, self.key), combined).convert();
result[0]
}
}
@@ -328,15 +329,15 @@ impl Hasher for AHasherStr {
fn write(&mut self, bytes: &[u8]) {
if bytes.len() > 8 {
self.0.write(bytes);
- self.0.enc = aesdec(self.0.sum, self.0.enc);
- self.0.enc = aesenc(aesenc(self.0.enc, self.0.key), self.0.enc);
+ self.0.enc = aesenc(self.0.sum, self.0.enc);
+ self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc);
} else {
add_in_length(&mut self.0.enc, bytes.len() as u64);
let value = read_small(bytes).convert();
self.0.sum = shuffle_and_add(self.0.sum, value);
- self.0.enc = aesdec(self.0.sum, self.0.enc);
- self.0.enc = aesenc(aesenc(self.0.enc, self.0.key), self.0.enc);
+ self.0.enc = aesenc(self.0.sum, self.0.enc);
+ self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc);
}
}
diff --git a/vendor/ahash/src/convert.rs b/vendor/ahash/src/convert.rs
index fc47baabb..712eae163 100644
--- a/vendor/ahash/src/convert.rs
+++ b/vendor/ahash/src/convert.rs
@@ -7,13 +7,13 @@ macro_rules! convert {
impl Convert<$b> for $a {
#[inline(always)]
fn convert(self) -> $b {
- unsafe { core::mem::transmute::<$a, $b>(self) }
+ zerocopy::transmute!(self)
}
}
impl Convert<$a> for $b {
#[inline(always)]
fn convert(self) -> $a {
- unsafe { core::mem::transmute::<$b, $a>(self) }
+ zerocopy::transmute!(self)
}
}
};
@@ -65,8 +65,7 @@ macro_rules! as_array {
{
#[inline(always)]
fn as_array<T>(slice: &[T]) -> &[T; $len] {
- assert_eq!(slice.len(), $len);
- unsafe { &*(slice.as_ptr() as *const [_; $len]) }
+ core::convert::TryFrom::try_from(slice).unwrap()
}
as_array($input)
}
diff --git a/vendor/ahash/src/hash_quality_test.rs b/vendor/ahash/src/hash_quality_test.rs
index 8f13d2421..25356e457 100644
--- a/vendor/ahash/src/hash_quality_test.rs
+++ b/vendor/ahash/src/hash_quality_test.rs
@@ -1,5 +1,5 @@
use core::hash::{Hash, Hasher};
-use std::collections::HashMap;
+use std::collections::{HashMap};
fn assert_sufficiently_different(a: u64, b: u64, tolerance: i32) {
let (same_byte_count, same_nibble_count) = count_same_bytes_and_nibbles(a, b);
@@ -71,12 +71,8 @@ fn test_no_full_collisions<T: Hasher>(gen_hash: impl Fn() -> T) {
gen_combinations(&options, 7, Vec::new(), &mut combinations);
let mut map: HashMap<u64, Vec<u8>> = HashMap::new();
for combination in combinations {
- let array = unsafe {
- let (begin, middle, end) = combination.align_to::<u8>();
- assert_eq!(0, begin.len());
- assert_eq!(0, end.len());
- middle.to_vec()
- };
+ use zerocopy::AsBytes;
+ let array = combination.as_slice().as_bytes().to_vec();
let mut hasher = gen_hash();
hasher.write(&array);
let hash = hasher.finish();
@@ -342,6 +338,28 @@ fn test_length_extension<T: Hasher>(hasher: impl Fn(u128, u128) -> T) {
}
}
+fn test_sparse<T: Hasher>(hasher: impl Fn() -> T) {
+ let mut buf = [0u8; 256];
+ let mut hashes = HashMap::new();
+ for idx_1 in 0..256 {
+ for idx_2 in idx_1+1..256 {
+ for value_1 in [1, 2, 4, 8, 16, 32, 64, 128] {
+ for value_2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 16, 17, 18, 20, 24, 31, 32, 33, 48, 64, 96, 127, 128, 129, 192, 254, 255] {
+ buf[idx_1] = value_1;
+ buf[idx_2] = value_2;
+ let hash_value = hash_with(&buf, &mut hasher());
+ let keys = hashes.entry(hash_value).or_insert(Vec::new());
+ keys.push((idx_1, value_1, idx_2, value_2));
+ buf[idx_1] = 0;
+ buf[idx_2] = 0;
+ }
+ }
+ }
+ }
+ hashes.retain(|_key, value| value.len() != 1);
+ assert_eq!(0, hashes.len(), "Collision with: {:?}", hashes);
+}
+
#[cfg(test)]
mod fallback_tests {
use crate::fallback_hash::*;
@@ -408,6 +426,12 @@ mod fallback_tests {
fn fallback_length_extension() {
test_length_extension(|a, b| AHasher::new_with_keys(a, b));
}
+
+ #[test]
+ fn test_no_sparse_collisions() {
+ test_sparse(|| AHasher::new_with_keys(0, 0));
+ test_sparse(|| AHasher::new_with_keys(1, 2));
+ }
}
///Basic sanity tests of the cypto properties of aHash.
@@ -501,4 +525,10 @@ mod aes_tests {
fn aes_length_extension() {
test_length_extension(|a, b| AHasher::test_with_keys(a, b));
}
+
+ #[test]
+ fn aes_no_sparse_collisions() {
+ test_sparse(|| AHasher::test_with_keys(0, 0));
+ test_sparse(|| AHasher::test_with_keys(1, 2));
+ }
}
diff --git a/vendor/ahash/src/operations.rs b/vendor/ahash/src/operations.rs
index ffd3b1a1a..23d4e22fa 100644
--- a/vendor/ahash/src/operations.rs
+++ b/vendor/ahash/src/operations.rs
@@ -1,4 +1,5 @@
use crate::convert::*;
+use zerocopy::transmute;
///This constant comes from Kunth's prng (Empirically it works better than those from splitmix32).
pub(crate) const MULTIPLE: u64 = 6364136223846793005;
@@ -55,8 +56,7 @@ pub(crate) fn shuffle(a: u128) -> u128 {
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
- use core::mem::transmute;
- unsafe { transmute(_mm_shuffle_epi8(transmute(a), transmute(SHUFFLE_MASK))) }
+ unsafe { transmute!(_mm_shuffle_epi8(transmute!(a), transmute!(SHUFFLE_MASK))) }
}
#[cfg(not(all(target_feature = "ssse3", not(miri))))]
{
@@ -81,13 +81,12 @@ pub(crate) fn shuffle_and_add(base: u128, to_add: u128) -> u128 {
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2", not(miri)))]
#[inline(always)]
pub(crate) fn add_by_64s(a: [u64; 2], b: [u64; 2]) -> [u64; 2] {
- use core::mem::transmute;
unsafe {
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
- transmute(_mm_add_epi64(transmute(a), transmute(b)))
+ transmute!(_mm_add_epi64(transmute!(a), transmute!(b)))
}
}
@@ -105,10 +104,9 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 {
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
- use core::mem::transmute;
unsafe {
- let value = transmute(value);
- transmute(_mm_aesenc_si128(value, transmute(xor)))
+ let value = transmute!(value);
+ transmute!(_mm_aesenc_si128(value, transmute!(xor)))
}
}
@@ -125,11 +123,9 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 {
use core::arch::aarch64::*;
#[cfg(target_arch = "arm")]
use core::arch::arm::*;
- use core::mem::transmute;
- unsafe {
- let value = transmute(value);
- transmute(vaesmcq_u8(vaeseq_u8(value, transmute(xor))))
- }
+ let res = unsafe { vaesmcq_u8(vaeseq_u8(transmute!(value), transmute!(0u128))) };
+ let value: u128 = transmute!(res);
+ xor ^ value
}
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)))]
@@ -140,10 +136,9 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 {
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
- use core::mem::transmute;
unsafe {
- let value = transmute(value);
- transmute(_mm_aesdec_si128(value, transmute(xor)))
+ let value = transmute!(value);
+ transmute!(_mm_aesdec_si128(value, transmute!(xor)))
}
}
@@ -160,11 +155,9 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 {
use core::arch::aarch64::*;
#[cfg(target_arch = "arm")]
use core::arch::arm::*;
- use core::mem::transmute;
- unsafe {
- let value = transmute(value);
- transmute(vaesimcq_u8(vaesdq_u8(value, transmute(xor))))
- }
+ let res = unsafe { vaesimcq_u8(vaesdq_u8(transmute!(value), transmute!(0u128))) };
+ let value: u128 = transmute!(res);
+ xor ^ value
}
#[allow(unused)]
@@ -207,7 +200,7 @@ mod test {
// #[cfg(target_arch = "x86_64")]
// use core::arch::x86_64::*;
// MASK.with(|mask| {
- // unsafe { transmute(_mm_shuffle_epi8(transmute(a), transmute(mask.get()))) }
+ // unsafe { transmute!(_mm_shuffle_epi8(transmute!(a), transmute!(mask.get()))) }
// })
// }
//