aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2023-02-15 18:51:28 +0100
committerJeff Vander Stoep <jeffv@google.com>2023-02-15 18:51:28 +0100
commit75621b093045ee537ab112250d394ba7978d3bce (patch)
tree0efdc811ebd9ccef231d3837fb955e1fb19898ff
parent457b5e09c59640b0c36eb0b8ce860c15a52d2af5 (diff)
downloadahash-75621b093045ee537ab112250d394ba7978d3bce.tar.gz
Upgrade ahash to 0.8.3
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/ahash For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: I60f5426f192bc9e0173cdbae5f30cf42dad66821
-rw-r--r--.cargo_vcs_info.json7
-rw-r--r--.github/workflows/rust.yml7
-rw-r--r--Android.bp3
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA14
-rw-r--r--README.md2
-rw-r--r--src/hash_map.rs3
-rw-r--r--src/hash_quality_test.rs14
-rw-r--r--src/hash_set.rs1
-rw-r--r--src/random_state.rs1
-rw-r--r--tests/bench.rs147
12 files changed, 69 insertions, 134 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 832d476..5f20ebf 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,6 @@
{
"git": {
- "sha1": "e77cab8c1e15bfc9f54dfd28bd8820c2a7bb27c4"
- }
-}
+ "sha1": "f9acd508bd89e7c5b2877a9510098100f9018d64"
+ },
+ "path_in_vcs": ""
+} \ No newline at end of file
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index ba596bf..c551724 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -32,6 +32,11 @@ jobs:
with:
command: test
args: --no-default-features --features compile-time-rng
+ - name: check fixed-seed
+ uses: actions-rs/cargo@v1
+ with:
+ command: check
+ args: --no-default-features --features std
- name: check
uses: actions-rs/cargo@v1
with:
@@ -148,4 +153,4 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
- args: --target wasm32-unknown-unknown
+ args: --target wasm32-unknown-unknown --no-default-features
diff --git a/Android.bp b/Android.bp
index 62b8b27..b117cd8 100644
--- a/Android.bp
+++ b/Android.bp
@@ -39,11 +39,10 @@ license {
rust_library {
name: "libahash",
- // has rustc warnings
host_supported: true,
crate_name: "ahash",
cargo_env_compat: true,
- cargo_pkg_version: "0.8.2",
+ cargo_pkg_version: "0.8.3",
srcs: ["src/lib.rs"],
edition: "2018",
arch: {
diff --git a/Cargo.toml b/Cargo.toml
index e251c70..a027c55 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "ahash"
-version = "0.8.2"
+version = "0.8.3"
authors = ["Tom Kaitchuck <Tom.Kaitchuck@gmail.com>"]
build = "./build.rs"
exclude = [
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index b11a4a9..9b19105 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "ahash"
-version = "0.8.2"
+version = "0.8.3"
authors = ["Tom Kaitchuck <Tom.Kaitchuck@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "A non-cryptographic hash function using AES-NI for high performance"
diff --git a/METADATA b/METADATA
index 45b1569..18aa68c 100644
--- a/METADATA
+++ b/METADATA
@@ -1,3 +1,7 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update rust/crates/ahash
+# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+
name: "ahash"
description: "A non-cryptographic hash function using AES-NI for high performance"
third_party {
@@ -7,13 +11,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/ahash/ahash-0.8.2.crate"
+ value: "https://static.crates.io/crates/ahash/ahash-0.8.3.crate"
}
- version: "0.8.2"
+ version: "0.8.3"
license_type: NOTICE
last_upgrade_date {
- year: 2022
- month: 12
- day: 1
+ year: 2023
+ month: 2
+ day: 15
}
}
diff --git a/README.md b/README.md
index efab7b2..18c421d 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# aHash ![Build Status](https://img.shields.io/github/workflow/status/tkaitchuck/ahash/Rust) ![Licence](https://img.shields.io/crates/l/ahash) ![Downloads](https://img.shields.io/crates/d/ahash)
+# aHash ![Build Status](https://img.shields.io/github/actions/workflow/status/tkaitchuck/aHash/rust.yml?branch=master) ![Licence](https://img.shields.io/crates/l/ahash) ![Downloads](https://img.shields.io/crates/d/ahash)
AHash is the [fastest](https://github.com/tkaitchuck/aHash/blob/master/compare/readme.md#Speed),
[DOS resistant hash](https://github.com/tkaitchuck/aHash/wiki/How-aHash-is-resists-DOS-attacks) currently available in Rust.
diff --git a/src/hash_map.rs b/src/hash_map.rs
index c1cb57d..2b6fbdc 100644
--- a/src/hash_map.rs
+++ b/src/hash_map.rs
@@ -1,6 +1,6 @@
use std::borrow::Borrow;
-use std::collections::{hash_map, HashMap};
use std::collections::hash_map::{IntoKeys, IntoValues};
+use std::collections::{hash_map, HashMap};
use std::fmt::{self, Debug};
use std::hash::{BuildHasher, Hash};
use std::iter::FromIterator;
@@ -14,7 +14,6 @@ use serde::{
};
use crate::RandomState;
-use crate::random_state::RandomSource;
/// A [`HashMap`](std::collections::HashMap) using [`RandomState`](crate::RandomState) to hash the items.
/// (Requires the `std` feature to be enabled.)
diff --git a/src/hash_quality_test.rs b/src/hash_quality_test.rs
index bd85edd..8f13d24 100644
--- a/src/hash_quality_test.rs
+++ b/src/hash_quality_test.rs
@@ -50,7 +50,7 @@ fn count_same_bytes_and_nibbles(a: u64, b: u64) -> (i32, i32) {
(same_byte_count, same_nibble_count)
}
-fn gen_combinations(options: &[u32; 8], depth: u32, so_far: Vec<u32>, combinations: &mut Vec<Vec<u32>>) {
+fn gen_combinations(options: &[u32; 11], depth: u32, so_far: Vec<u32>, combinations: &mut Vec<Vec<u32>>) {
if depth == 0 {
return;
}
@@ -63,8 +63,9 @@ fn gen_combinations(options: &[u32; 8], depth: u32, so_far: Vec<u32>, combinatio
}
fn test_no_full_collisions<T: Hasher>(gen_hash: impl Fn() -> T) {
- let options: [u32; 8] = [
- 0x00000000, 0x20000000, 0x40000000, 0x60000000, 0x80000000, 0xA0000000, 0xC0000000, 0xE0000000,
+ let options: [u32; 11] = [
+ 0x00000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0xF0000000,
+ 1, 2, 4, 8, 15
];
let mut combinations = Vec::new();
gen_combinations(&options, 7, Vec::new(), &mut combinations);
@@ -89,7 +90,7 @@ fn test_no_full_collisions<T: Hasher>(gen_hash: impl Fn() -> T) {
map.insert(hash, array);
}
}
- assert_eq!(2396744, map.len());
+ assert_eq!(21435887, map.len()); //11^7 + 11^6 ...
}
fn test_keys_change_output<T: Hasher>(constructor: impl Fn(u128, u128) -> T) {
@@ -150,9 +151,10 @@ fn assert_each_byte_differs(num: u64, base: u64, alternitives: Vec<u64>) {
assert_eq!(
core::u64::MAX,
changed_bits,
- "Bits changed: {:x} on num: {:?}",
+ "Bits changed: {:x} on num: {:?}. base {:x}",
changed_bits,
- num
+ num,
+ base
);
}
diff --git a/src/hash_set.rs b/src/hash_set.rs
index 8d1341a..d03bef5 100644
--- a/src/hash_set.rs
+++ b/src/hash_set.rs
@@ -1,5 +1,4 @@
use crate::RandomState;
-use crate::random_state::RandomSource;
use std::collections::{hash_set, HashSet};
use std::fmt::{self, Debug};
use std::hash::{BuildHasher, Hash};
diff --git a/src/random_state.rs b/src/random_state.rs
index 5b85726..6bdd05f 100644
--- a/src/random_state.rs
+++ b/src/random_state.rs
@@ -114,6 +114,7 @@ cfg_if::cfg_if! {
&RAND
}
} else {
+ #[inline]
fn get_fixed_seeds() -> &'static [[u64; 4]; 2] {
&[PI, PI2]
}
diff --git a/tests/bench.rs b/tests/bench.rs
index 84a3739..5bc0fc9 100644
--- a/tests/bench.rs
+++ b/tests/bench.rs
@@ -3,60 +3,33 @@
use ahash::{AHasher, RandomState};
use criterion::*;
use fxhash::FxHasher;
+use rand::Rng;
use std::collections::hash_map::DefaultHasher;
use std::hash::{BuildHasherDefault, Hash, Hasher};
-#[cfg(any(
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
+// Needs to be in sync with `src/lib.rs`
+const AHASH_IMPL: &str = if cfg!(any(
all(
- any(target_arch = "arm", target_arch = "aarch64"),
- any(target_feature = "aes", target_feature = "crypto"),
- not(miri),
- feature = "stdsimd"
- )
-))]
-fn aeshash<H: Hash>(b: &H) -> u64 {
- let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
- build_hasher.hash_one(b)
-}
-#[cfg(not(any(
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(
- any(target_arch = "arm", target_arch = "aarch64"),
- any(target_feature = "aes", target_feature = "crypto"),
+ any(target_arch = "x86", target_arch = "x86_64"),
+ target_feature = "aes",
not(miri),
- feature = "stdsimd"
- )
-)))]
-fn aeshash<H: Hash>(_b: &H) -> u64 {
- panic!("aes must be enabled")
-}
-
-#[cfg(not(any(
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
+ ),
all(
any(target_arch = "arm", target_arch = "aarch64"),
any(target_feature = "aes", target_feature = "crypto"),
not(miri),
- feature = "stdsimd"
- )
-)))]
-fn fallbackhash<H: Hash>(b: &H) -> u64 {
+ feature = "stdsimd",
+ ),
+)) {
+ "aeshash"
+} else {
+ "fallbackhash"
+};
+
+fn ahash<H: Hash>(b: &H) -> u64 {
let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
build_hasher.hash_one(b)
}
-#[cfg(any(
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(
- any(target_arch = "arm", target_arch = "aarch64"),
- any(target_feature = "aes", target_feature = "crypto"),
- not(miri),
- feature = "stdsimd"
- )
-))]
-fn fallbackhash<H: Hash>(_b: &H) -> u64 {
- panic!("aes must be disabled")
-}
fn fnvhash<H: Hash>(b: &H) -> u64 {
let mut hasher = fnv::FnvHasher::default();
@@ -98,72 +71,44 @@ fn gen_strings() -> Vec<String> {
.collect()
}
-const U8_VALUE: u8 = 123;
-const U16_VALUE: u16 = 1234;
-const U32_VALUE: u32 = 12345678;
-const U64_VALUE: u64 = 1234567890123456;
-const U128_VALUE: u128 = 12345678901234567890123456789012;
+macro_rules! bench_inputs {
+ ($group:ident, $hash:ident) => {
+ // Number of iterations per batch should be high enough to hide timing overhead.
+ let size = BatchSize::NumIterations(2_000);
-#[cfg(target_feature = "aes")]
-fn bench_ahash(c: &mut Criterion) {
- let mut group = c.benchmark_group("aeshash");
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(aeshash(s))));
+ let mut rng = rand::thread_rng();
+ $group.bench_function("u8", |b| b.iter_batched(|| rng.gen::<u8>(), |v| $hash(&v), size));
+ $group.bench_function("u16", |b| b.iter_batched(|| rng.gen::<u16>(), |v| $hash(&v), size));
+ $group.bench_function("u32", |b| b.iter_batched(|| rng.gen::<u32>(), |v| $hash(&v), size));
+ $group.bench_function("u64", |b| b.iter_batched(|| rng.gen::<u64>(), |v| $hash(&v), size));
+ $group.bench_function("u128", |b| b.iter_batched(|| rng.gen::<u128>(), |v| $hash(&v), size));
+ $group.bench_with_input("strings", &gen_strings(), |b, s| b.iter(|| $hash(black_box(s))));
+ };
}
-#[cfg(not(target_feature = "aes"))]
-fn bench_fallback(c: &mut Criterion) {
- let mut group = c.benchmark_group("fallback");
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(fallbackhash(s))));
+fn bench_ahash(c: &mut Criterion) {
+ let mut group = c.benchmark_group(AHASH_IMPL);
+ bench_inputs!(group, ahash);
}
fn bench_fx(c: &mut Criterion) {
let mut group = c.benchmark_group("fx");
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(fxhash(s))));
+ bench_inputs!(group, fxhash);
}
fn bench_fnv(c: &mut Criterion) {
let mut group = c.benchmark_group("fnv");
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(fnvhash(s))));
+ bench_inputs!(group, fnvhash);
}
fn bench_sea(c: &mut Criterion) {
let mut group = c.benchmark_group("sea");
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(seahash(s))));
+ bench_inputs!(group, seahash);
}
fn bench_sip(c: &mut Criterion) {
let mut group = c.benchmark_group("sip");
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(siphash(s))));
+ bench_inputs!(group, siphash);
}
fn bench_map(c: &mut Criterion) {
@@ -242,32 +187,12 @@ fn bench_map(c: &mut Criterion) {
criterion_main!(benches);
-#[cfg(any(
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(
- any(target_arch = "arm", target_arch = "aarch64"),
- any(target_feature = "aes", target_feature = "crypto"),
- not(miri),
- feature = "stdsimd"
- )
-))]
-criterion_group!(benches, bench_ahash, bench_fx, bench_fnv, bench_sea, bench_sip);
-
-#[cfg(not(any(
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(
- any(target_arch = "arm", target_arch = "aarch64"),
- any(target_feature = "aes", target_feature = "crypto"),
- not(miri),
- feature = "stdsimd"
- )
-)))]
criterion_group!(
benches,
- bench_fallback,
+ bench_ahash,
bench_fx,
bench_fnv,
bench_sea,
bench_sip,
- bench_map,
+ bench_map
);