Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into release 0.8 branch #204

Merged
merged 5 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 76 additions & 116 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,191 +6,151 @@ 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
- 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
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
- 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
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
- 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:
command: test
args: --target i686-unknown-linux-gnu
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
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
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:
command: test
args: --target x86_64-unknown-linux-gnu
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
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
msrv:
name: MSRV
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install 1.60.0
uses: actions-rs/toolchain@v1
with:
toolchain: 1.60.0
- name: check
uses: actions-rs/cargo@v1
with:
command: check
targets: wasm32-unknown-unknown
- run: cargo check --target wasm32-unknown-unknown --no-default-features
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions compare/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
AHash outperforms wyHash across all input sizes, regardless of which CPU instructions are available.
24 changes: 12 additions & 12 deletions src/hash_quality_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,40 +108,40 @@ fn test_keys_change_output<T: Hasher>(constructor: impl Fn(u128, u128) -> T) {
fn test_input_affect_every_byte<T: Hasher>(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);
}
}

///Ensures that for every bit in the output there is some value for each byte in the key that flips it.
fn test_keys_affect_every_byte<H: Hash, T: Hasher>(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<u64>) {
fn assert_each_byte_differs(num: u64, base: u64, alternatives: Vec<u64>) {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use ahash::AHashMap;
let mut map: AHashMap<i32, i32> = 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

Expand Down
26 changes: 26 additions & 0 deletions tests/map_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Box<String>>::default();
m.insert(Box::from("hello".to_string()));
assert!(m.contains(&"hello".to_string()));

let mut m = ahash::HashSet::<String>::default();
m.insert("hello".to_string());
assert!(m.contains("hello"));

let mut m = ahash::HashSet::<Box<[u8]>>::default();
m.insert(Box::from(&b"hello"[..]));
assert!(m.contains(&b"hello"[..]));
}


fn ahash_vec<H: Hash>(b: &Vec<H>) -> u64 {
let mut total: u64 = 0;
for item in b {
Expand Down