From 853dc60a08386f8e71765beee7f1d5b1cdc1f3d5 Mon Sep 17 00:00:00 2001 From: Dirk Stolle Date: Tue, 2 Jan 2024 18:07:04 +0100 Subject: [PATCH 1/5] Fix some typos (#192) --- compare/readme.md | 4 ++-- src/hash_quality_test.rs | 24 ++++++++++++------------ src/lib.rs | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compare/readme.md b/compare/readme.md index 58146e5..e7a6c53 100644 --- a/compare/readme.md +++ b/compare/readme.md @@ -25,7 +25,7 @@ Even the fallback algorithm is in the top 5 in terms of throughput, beating out aHash is the fastest non-trivial hasher implementation in Rust. Below is a comparison with 10 other popular hashing algorithms. -![Hasher perfromance](https://docs.google.com/spreadsheets/d/e/2PACX-1vSK7Li2nS-Bur9arAYF9IfT37MP-ohAe1v19lZu5fd9MajI1fSveLAQZyEie4Ea9k5-SWHTff7nL2DW/pubchart?oid=1323618938&format=image) +![Hasher performance](https://docs.google.com/spreadsheets/d/e/2PACX-1vSK7Li2nS-Bur9arAYF9IfT37MP-ohAe1v19lZu5fd9MajI1fSveLAQZyEie4Ea9k5-SWHTff7nL2DW/pubchart?oid=1323618938&format=image) ## DOS resistance @@ -120,4 +120,4 @@ Similarly, wyHash is targeted at hashmaps. WyHash is quite fast, but is not DOS There are fixed strings which when encountered caused the internal state to reset. This makes wyHash trivial to attack. -AHash outperforms wyHash across all input sizes, regardless of which CPU instructions are available. \ No newline at end of file +AHash outperforms wyHash across all input sizes, regardless of which CPU instructions are available. diff --git a/src/hash_quality_test.rs b/src/hash_quality_test.rs index 4f6091a..43f2aeb 100644 --- a/src/hash_quality_test.rs +++ b/src/hash_quality_test.rs @@ -108,13 +108,13 @@ fn test_keys_change_output(constructor: impl Fn(u128, u128) -> T) { fn test_input_affect_every_byte(constructor: impl Fn(u128, u128) -> T) { let base = hash_with(&0, constructor(0, 0)); for shift in 0..16 { - let mut alternitives = vec![]; + let mut alternatives = vec![]; for v in 0..256 { let input = (v as u128) << (shift * 8); let hasher = constructor(0, 0); - alternitives.push(hash_with(&input, hasher)); + alternatives.push(hash_with(&input, hasher)); } - assert_each_byte_differs(shift, base, alternitives); + assert_each_byte_differs(shift, base, alternatives); } } @@ -122,26 +122,26 @@ fn test_input_affect_every_byte(constructor: impl Fn(u128, u128) -> T fn test_keys_affect_every_byte(item: H, constructor: impl Fn(u128, u128) -> T) { let base = hash_with(&item, constructor(0, 0)); for shift in 0..16 { - let mut alternitives1 = vec![]; - let mut alternitives2 = vec![]; + let mut alternatives1 = vec![]; + let mut alternatives2 = vec![]; for v in 0..256 { let input = (v as u128) << (shift * 8); let hasher1 = constructor(input, 0); let hasher2 = constructor(0, input); let h1 = hash_with(&item, hasher1); let h2 = hash_with(&item, hasher2); - alternitives1.push(h1); - alternitives2.push(h2); + alternatives1.push(h1); + alternatives2.push(h2); } - assert_each_byte_differs(shift, base, alternitives1); - assert_each_byte_differs(shift, base, alternitives2); + assert_each_byte_differs(shift, base, alternatives1); + assert_each_byte_differs(shift, base, alternatives2); } } -fn assert_each_byte_differs(num: u64, base: u64, alternitives: Vec) { +fn assert_each_byte_differs(num: u64, base: u64, alternatives: Vec) { let mut changed_bits = 0_u64; - for alternitive in alternitives { - changed_bits |= base ^ alternitive + for alternative in alternatives { + changed_bits |= base ^ alternative } assert_eq!( core::u64::MAX, diff --git a/src/lib.rs b/src/lib.rs index 2086513..500f430 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ use ahash::AHashMap; let mut map: AHashMap = AHashMap::new(); map.insert(12, 34); ``` -This avoids the need to type "RandomState". (For convience `From`, `Into`, and `Deref` are provided). +This avoids the need to type "RandomState". (For convenience `From`, `Into`, and `Deref` are provided). # Aliases From 1e6f01a4060d20a6a407b5cd89d0f5556405c5bc Mon Sep 17 00:00:00 2001 From: Dirk Stolle Date: Tue, 2 Jan 2024 18:07:59 +0100 Subject: [PATCH 2/5] Update GitHub Actions CI (#193) The following updates are performed: * update actions/checkout to v4 * replace unmaintained actions-rs/toolchain by dtolnay/rust-toolchain * replace unmaintained actions-rs/cargo by direct invocation of cargo --- .github/workflows/rust.yml | 156 +++++++++++-------------------------- 1 file changed, 47 insertions(+), 109 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1d440a5..6907df1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,191 +6,129 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install latest stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: toolchain: stable components: clippy - name: check nostd - uses: actions-rs/cargo@v1 - with: - command: check - args: --no-default-features + run: cargo check --no-default-features - name: test nostd - uses: actions-rs/cargo@v1 - with: - command: test - args: --no-default-features + run: cargo test --no-default-features - name: check constrandom - uses: actions-rs/cargo@v1 - with: - command: check - args: --no-default-features --features compile-time-rng + run: cargo check --no-default-features --features compile-time-rng - name: test constrandom - uses: actions-rs/cargo@v1 - with: - command: test - args: --no-default-features --features compile-time-rng + run: cargo test --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 + run: cargo check --no-default-features --features std - name: check - uses: actions-rs/cargo@v1 - with: - command: check + run: cargo check - name: test - uses: actions-rs/cargo@v1 - with: - command: test + run: cargo test nightly: name: nightly runs-on: ubuntu-latest env: RUSTFLAGS: -C target-cpu=native steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install latest nightly - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: toolchain: nightly - override: true components: clippy - name: check nightly - uses: actions-rs/cargo@v1 - with: - command: check - args: -Z msrv-policy + run: cargo check -Z msrv-policy - name: test nightly - uses: actions-rs/cargo@v1 - with: - command: test + run: cargo test - name: check serde - uses: actions-rs/cargo@v1 - with: - command: check - args: --features serde + run: cargo check --features serde - name: test serde - uses: actions-rs/cargo@v1 - with: - command: test - args: --features serde + run: cargo test --features serde linux_arm7: name: Linux ARMv7 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - target: armv7-unknown-linux-gnueabihf - - uses: actions-rs/cargo@v1 - with: - command: check - args: --target armv7-unknown-linux-gnueabihf + targets: armv7-unknown-linux-gnueabihf + - run: cargo check --target armv7-unknown-linux-gnueabihf aarch64-apple-darwin: name: Aarch64 Apple Darwin runs-on: macos-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - target: aarch64-apple-darwin - - uses: actions-rs/cargo@v1 - with: - command: check - args: --target aarch64-apple-darwin + targets: aarch64-apple-darwin + - run: cargo check --target aarch64-apple-darwin i686-unknown-linux-gnu: name: Linux i686 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - target: i686-unknown-linux-gnu + targets: i686-unknown-linux-gnu - name: Install cross compile tools run: sudo apt-get install -y gcc-multilib libc6-i386 libc6-dev-i386 - - uses: actions-rs/cargo@v1 - with: - command: check - args: --target i686-unknown-linux-gnu - - uses: actions-rs/cargo@v1 - with: - command: test - args: --target i686-unknown-linux-gnu + - run: cargo check --target i686-unknown-linux-gnu + - run: cargo test --target i686-unknown-linux-gnu x86_64-unknown-linux-gnu: name: Linux x86_64 - nightly runs-on: ubuntu-latest env: RUSTFLAGS: -C target-cpu=skylake -C target-feature=+aes steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: nightly - override: true - target: x86_64-unknown-linux-gnu - - uses: actions-rs/cargo@v1 - with: - command: check - args: --target x86_64-unknown-linux-gnu - - uses: actions-rs/cargo@v1 - with: - command: test - args: --target x86_64-unknown-linux-gnu + targets: x86_64-unknown-linux-gnu + - run: cargo check --target x86_64-unknown-linux-gnu + - run: cargo test --target x86_64-unknown-linux-gnu thumbv6m: name: thumbv6m runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - target: thumbv6m-none-eabi - - uses: actions-rs/cargo@v1 - with: - command: check - args: --target thumbv6m-none-eabi --no-default-features + targets: thumbv6m-none-eabi + - run: cargo check --target thumbv6m-none-eabi --no-default-features wasm32-unknown-unknown: name: wasm runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - target: wasm32-unknown-unknown - - uses: actions-rs/cargo@v1 - with: - command: check - args: --target wasm32-unknown-unknown --no-default-features + targets: wasm32-unknown-unknown + - run: cargo check --target wasm32-unknown-unknown --no-default-features msrv: name: MSRV runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install 1.60.0 - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: toolchain: 1.60.0 - name: check - uses: actions-rs/cargo@v1 - with: - command: check + run: cargo check no_std: name: no-std build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: nightly - override: true - - uses: actions-rs/cargo@v1 - with: - command: build - args: --manifest-path=no_std_test/Cargo.toml + - run: cargo build --manifest-path=no_std_test/Cargo.toml From 79732df24cd44f8112b6b4583c0cf2c97dddc65d Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Sat, 10 Feb 2024 15:52:54 -0800 Subject: [PATCH 3/5] Add test for key ref invariance Signed-off-by: Tom Kaitchuck --- tests/map_tests.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/map_tests.rs b/tests/map_tests.rs index 8d798a0..bdf37d8 100644 --- a/tests/map_tests.rs +++ b/tests/map_tests.rs @@ -200,6 +200,32 @@ fn test_ahash_alias_set_construction() { set.insert(1); } + +#[cfg(feature = "std")] +#[test] +fn test_key_ref() { + let mut map = ahash::HashMap::default(); + map.insert(1, "test"); + assert_eq!(Some((1, "test")), map.remove_entry(&1)); + + let mut map = ahash::HashMap::default(); + map.insert(&1, "test"); + assert_eq!(Some((&1, "test")), map.remove_entry(&&1)); + + let mut m = ahash::HashSet::>::default(); + m.insert(Box::from("hello".to_string())); + assert!(m.contains(&"hello".to_string())); + + let mut m = ahash::HashSet::::default(); + m.insert("hello".to_string()); + assert!(m.contains("hello")); + + let mut m = ahash::HashSet::>::default(); + m.insert(Box::from(&b"hello"[..])); + assert!(m.contains(&b"hello"[..])); +} + + fn ahash_vec(b: &Vec) -> u64 { let mut total: u64 = 0; for item in b { From 71f474247b653cdb96d9dfa64e7c31ed92a6b48b Mon Sep 17 00:00:00 2001 From: Jeffrey Vo Date: Sun, 11 Feb 2024 15:52:31 +1100 Subject: [PATCH 4/5] Bump rust-version to 1.72.0 (#196) * Bump rust-version to 1.72.0 * Bump rust version in MSRC CI check --- .github/workflows/rust.yml | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6907df1..327397e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -117,10 +117,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Install 1.60.0 + - name: Install 1.72.0 uses: dtolnay/rust-toolchain@master with: - toolchain: 1.60.0 + toolchain: 1.72.0 - name: check run: cargo check no_std: diff --git a/Cargo.toml b/Cargo.toml index 7f2901f..2d65614 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" readme = "README.md" build = "./build.rs" exclude = ["/smhasher", "/benchmark_tools"] -rust-version = "1.60.0" +rust-version = "1.72.0" [lib] name = "ahash" From 722ca8a0f17ccd64c5c51f8083c1897ae56fbd06 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Sat, 10 Feb 2024 21:06:48 -0800 Subject: [PATCH 5/5] Increase the MSRV presubmit checks to include multiple architectures (#197) Increase the MSRV presubmit checks to include multiple architectures Signed-off-by: Tom Kaitchuck --- .github/workflows/rust.yml | 48 +++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 327397e..7e28cda 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -56,6 +56,12 @@ jobs: toolchain: stable targets: armv7-unknown-linux-gnueabihf - run: cargo check --target armv7-unknown-linux-gnueabihf + - name: Install 1.72.0 + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.72.0 + targets: armv7-unknown-linux-gnueabihf + - run: cargo +1.72.0 check --target armv7-unknown-linux-gnueabihf aarch64-apple-darwin: name: Aarch64 Apple Darwin runs-on: macos-latest @@ -66,6 +72,14 @@ jobs: toolchain: stable targets: aarch64-apple-darwin - run: cargo check --target aarch64-apple-darwin + - run: cargo test + - run: cargo test --no-default-features --features compile-time-rng + - name: Install 1.72.0 + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.72.0 + targets: aarch64-apple-darwin + - run: cargo +1.72.0 check --target aarch64-apple-darwin i686-unknown-linux-gnu: name: Linux i686 runs-on: ubuntu-latest @@ -79,8 +93,18 @@ jobs: run: sudo apt-get install -y gcc-multilib libc6-i386 libc6-dev-i386 - run: cargo check --target i686-unknown-linux-gnu - run: cargo test --target i686-unknown-linux-gnu + - name: check constrandom + run: cargo check --no-default-features --features compile-time-rng --target i686-unknown-linux-gnu + - name: Install 1.72.0 + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.72.0 + targets: i686-unknown-linux-gnu + - run: cargo +1.72.0 check --target i686-unknown-linux-gnu + - name: check constrandom + run: cargo +1.72.0 check --no-default-features --features compile-time-rng --target i686-unknown-linux-gnu x86_64-unknown-linux-gnu: - name: Linux x86_64 - nightly + name: Linux x86_64 runs-on: ubuntu-latest env: RUSTFLAGS: -C target-cpu=skylake -C target-feature=+aes @@ -92,6 +116,15 @@ jobs: targets: x86_64-unknown-linux-gnu - run: cargo check --target x86_64-unknown-linux-gnu - run: cargo test --target x86_64-unknown-linux-gnu + - name: check constrandom + run: cargo check --no-default-features --features compile-time-rng --target x86_64-unknown-linux-gnu + - name: Install 1.72.0 + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.72.0 + - run: cargo +1.72.0 check --target x86_64-unknown-linux-gnu + - name: check constrandom + run: cargo +1.72.0 check --no-default-features --features compile-time-rng --target x86_64-unknown-linux-gnu thumbv6m: name: thumbv6m runs-on: ubuntu-latest @@ -112,17 +145,6 @@ jobs: toolchain: stable targets: wasm32-unknown-unknown - run: cargo check --target wasm32-unknown-unknown --no-default-features - msrv: - name: MSRV - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install 1.72.0 - uses: dtolnay/rust-toolchain@master - with: - toolchain: 1.72.0 - - name: check - run: cargo check no_std: name: no-std build runs-on: ubuntu-latest @@ -131,4 +153,4 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: nightly - - run: cargo build --manifest-path=no_std_test/Cargo.toml + - run: cargo build --manifest-path=no_std_test/Cargo.toml \ No newline at end of file