Skip to content

Commit 872959e

Browse files
authored
Merge pull request #101 from shepmaster/v2
Rewrite for version 2
2 parents 5f3f3a3 + 6d4ffd4 commit 872959e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+6911
-4036
lines changed

.github/workflows/ci.yml

+126-59
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,173 @@ on: push
22

33
name: Continuous integration
44

5+
env:
6+
RUSTFLAGS: -D warnings
7+
RUSTDOCFLAGS: -D warnings
8+
59
jobs:
610
library:
7-
runs-on: ubuntu-latest
811
strategy:
912
matrix:
13+
platform:
14+
- ubuntu-latest
15+
1016
rust:
1117
- stable
1218
- beta
1319
- nightly
14-
- 1.37.0 # MSRV
20+
- 1.81.0 # MSRV
21+
22+
include:
23+
- platform: macos-latest # This serves as our aarch64 / arm64 runner
24+
rust: stable
25+
26+
- platform: windows-latest
27+
rust: stable
28+
29+
runs-on: ${{ matrix.platform }}
1530

1631
steps:
17-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@v4
1833

19-
- uses: actions-rs/toolchain@v1
34+
- run: git submodule update --init --recursive
35+
36+
- uses: dtolnay/rust-toolchain@master
2037
with:
21-
profile: minimal
2238
toolchain: ${{ matrix.rust }}
23-
override: true
24-
components: rustfmt, clippy
2539

26-
- uses: actions-rs/cargo@v1
27-
with:
28-
command: build
40+
- name: Unit Tests
41+
run: cargo test --all-features
2942

30-
- uses: actions-rs/cargo@v1
31-
with:
32-
command: test
43+
- name: Property Tests
44+
run: cargo test -p comparison --all-features
3345

34-
- uses: actions-rs/cargo@v1
35-
with:
36-
command: test
37-
args: --all-features
46+
miri:
47+
runs-on: ubuntu-latest
48+
env:
49+
MIRIFLAGS: --cfg _internal_xxhash3_force_scalar
50+
51+
steps:
52+
- uses: actions/checkout@v4
3853

39-
- uses: actions-rs/cargo@v1
54+
- uses: dtolnay/rust-toolchain@master
4055
with:
41-
command: fmt
42-
args: --all -- --check
43-
if: ${{ matrix.rust == 'stable' }}
56+
toolchain: nightly
57+
components: miri
4458

45-
- uses: actions-rs/cargo@v1
59+
- name: Unsafe Code
60+
run: cargo miri test --all-features
61+
62+
- name: Big Endian Platform
63+
run: cargo miri test --all-features --target s390x-unknown-linux-gnu
64+
65+
lints:
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- run: git submodule update --init --recursive
72+
73+
- uses: dtolnay/rust-toolchain@master
4674
with:
47-
command: clippy
48-
args: --all-features -- -D warnings
49-
if: ${{ matrix.rust == 'stable' }}
75+
toolchain: stable
76+
components: rustfmt, clippy
77+
78+
- run: cargo fmt --all
79+
80+
- run: cargo clippy --all --all-targets --all-features
81+
82+
- run: cargo doc --all-features
5083

5184
no-std:
5285
runs-on: ubuntu-latest
5386

5487
steps:
55-
- uses: actions/checkout@v2
88+
- uses: actions/checkout@v4
5689

57-
- uses: actions-rs/toolchain@v1
90+
- uses: dtolnay/rust-toolchain@master
5891
with:
59-
profile: minimal
6092
toolchain: stable
61-
target: thumbv6m-none-eabi
62-
override: true
93+
targets: thumbv6m-none-eabi
6394

64-
- uses: actions-rs/cargo@v1
65-
with:
66-
command: build
67-
args: --no-default-features --target thumbv6m-none-eabi --lib
95+
- run: >
96+
cargo build
97+
--no-default-features
98+
--features=xxhash32,xxhash64,xxhash3_64
99+
--target thumbv6m-none-eabi
68100
69-
compatibility-tests:
101+
features:
70102
runs-on: ubuntu-latest
71-
strategy:
72-
matrix:
73-
test:
74-
- digest_0_8
75-
- digest_0_9
103+
104+
env:
105+
IMPLEMENTATIONS: xxhash32 xxhash64 xxhash3_64
106+
FEATURE_SET: random serialize std alloc
76107

77108
steps:
78-
- uses: actions/checkout@v2
109+
- uses: actions/checkout@v4
110+
111+
- run: git submodule update --init --recursive
79112

80-
- uses: actions-rs/toolchain@v1
113+
- uses: dtolnay/rust-toolchain@master
81114
with:
82-
profile: minimal
83115
toolchain: stable
84-
override: true
85116

86-
- uses: actions-rs/cargo@v1
87-
with:
88-
command: test
89-
args: --manifest-path "compatibility-tests/${{ matrix.test }}/Cargo.toml"
117+
- name: Compute Powerset
118+
shell: "ruby {0}"
119+
run: |
120+
features = ENV['FEATURE_SET']
121+
.split(' ')
122+
.reduce([[]]) { |ps, i| ps + ps.map { |e| e + [i] } }
123+
.map { |s| s.join(',') }
124+
.join(" ")
125+
126+
File.open(ENV['GITHUB_ENV'], 'a') { |f| f.write("FEATURES=#{features}") }
90127
91-
big_endian:
128+
- name: Check implementations with features
129+
run: |
130+
for impl in ${IMPLEMENTATIONS}; do
131+
echo "::group::Implementation ${impl}"
132+
133+
# Check the implementation by itself
134+
cargo check --no-default-features --features="${impl}"
135+
136+
# And with extra features
137+
for feature in ${FEATURES}; do
138+
echo "::group::Features ${feature}"
139+
cargo check --no-default-features --features="${impl},${feature}"
140+
echo "::endgroup::"
141+
done
142+
143+
echo ::endgroup::
144+
done
145+
146+
minimal-versions:
92147
runs-on: ubuntu-latest
148+
93149
steps:
94-
- name: Checkout code
95-
uses: actions/checkout@v3
150+
- uses: actions/checkout@v4
96151

97-
- name: Set up QEMU
98-
uses: docker/setup-qemu-action@v1
152+
- run: git submodule update --init --recursive
153+
154+
- uses: dtolnay/rust-toolchain@master
99155
with:
100-
platforms: s390x
156+
toolchain: 1.81.0 # MSRV
101157

102-
- name: Cross test
103-
uses: actions-rs/cargo@v1
158+
- uses: dtolnay/rust-toolchain@master
104159
with:
105-
use-cross: true
106-
command: test
107-
args: --target s390x-unknown-linux-gnu
160+
toolchain: nightly
161+
162+
- name: Remove non-essential dependencies
163+
run: |
164+
# Remove workspace dependencies
165+
sed -i '/\[workspace]/,/#END-\[workspace]/d' Cargo.toml
166+
167+
# Remove dev-dependencies
168+
sed -i '/\[dev-dependencies]/,/#END-\[dev-dependencies]/d' Cargo.toml
169+
170+
- name: Downgrade to minimal dependencies
171+
run: |
172+
cargo +nightly -Z minimal-versions update
173+
174+
- run: cargo +1.81.0 build --all-features

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
target
2-
Cargo.lock
1+
/Cargo.lock
2+
/target

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "comparison/xxHash"]
2-
path = comparison/xxHash
3-
url = https://github.com/Cyan4973/xxHash.git
1+
[submodule "xxHash"]
2+
path = xx_hash-sys/xxHash
3+
url = https://github.com/Cyan4973/xxHash.git

CHANGELOG.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.0.0] - Unreleased
9+
10+
[2.0.0]: https://github.com/shepmaster/twox-hash/tree/v2.0.0
11+
12+
This release is a complete rewrite of the crate, including
13+
reorganization of the code. The XXH3 algorithm now matches the 0.8
14+
release of the reference C xxHash implementation.
15+
16+
### Added
17+
18+
- `XxHash32::oneshot` and `XxHash64::oneshot` can perform hashing with
19+
zero allocation and generally improved performance. If you have code
20+
that creates a hasher and hashes a slice of bytes exactly once, you
21+
are strongly encouraged to use the new functions. This might look
22+
like:
23+
24+
```rust
25+
// Before
26+
let mut hasher = XxHash64::new(); // or XxHash32, or with seeds
27+
some_bytes.hash(&mut hasher);
28+
let hash = hasher.finish();
29+
30+
// After
31+
let hash = XxHash64::oneshot(some_bytes);
32+
```
33+
34+
- There is a feature flag for each hashing implementation. It is
35+
recommended that you opt-out of the crate's default features and
36+
only select the implementations you need to improve compile speed.
37+
38+
### Changed
39+
40+
- The crates minimum supported Rust version (MSRV) is now 1.81.
41+
42+
- Functional and performance comparisons are made against the
43+
reference C xxHash library version 0.8.2, which includes a stable
44+
XXH3 algorithm.
45+
46+
- Support for randomly-generated hasher instances is now behind the
47+
`random` feature flag. It was previously combined with the `std`
48+
feature flag.
49+
50+
### Removed
51+
52+
- The deprecated type aliases `XxHash` and `RandomXxHashBuilder` have
53+
been removed. Replace them with `XxHash64` and
54+
`xxhash64::RandomState` respectively.
55+
56+
- `RandomXxHashBuilder32` and `RandomXxHashBuilder64` are no longer
57+
available at the top-level of the crate. Replace them with
58+
`xxhash32::RandomState` and ``xxhash64::RandomState` respectively.
59+
60+
- `Xxh3Hash64` and `xx3::Hash64` have been renamed to `XxHash3_64` and
61+
`xxhash3_64::Hasher` respectively.
62+
63+
- The free functions `xxh3::hash64`, `xxh3::hash64_with_seed`, and
64+
`xxh3::hash64_with_secret` are now associated functions of
65+
`xxhash3_64::Hasher`: `oneshot`, `oneshot_with_seed` and
66+
`oneshot_with_secret`. Note that the argument order has changed.
67+
68+
- Support for the [digest][] crate has been removed. The digest crate
69+
is for **cryptographic** hash functions and xxHash is
70+
**non-cryptographic**.
71+
72+
- `XxHash32` and `XxHash64` no longer implement `Copy`. This prevents
73+
accidentally mutating a duplicate instance of the state instead of
74+
the original state. `Clone` is still implemented so you can make
75+
deliberate duplicates.
76+
77+
- The XXH3 128-bit variant is not yet re-written. Work is in progress
78+
for this.
79+
80+
- We no longer provide support for randomly-generated instances of the
81+
XXH3 64-bit variant. The XXH3 algorithm takes both a seed and a
82+
secret as input and deciding what to randomize is non-trivial and
83+
can have negative impacts on performance.
84+
85+
[digest]: https://docs.rs/digest/latest/digest/

Cargo.toml

+40-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
name = "twox-hash"
33
version = "1.6.3"
44
authors = ["Jake Goulding <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
6+
rust-version = "1.81"
67

78
description = "A Rust implementation of the XXHash and XXH3 algorithms"
89
readme = "README.md"
@@ -14,19 +15,45 @@ documentation = "https://docs.rs/twox-hash/"
1415

1516
license = "MIT"
1617

18+
[workspace]
19+
members = [
20+
"asmasm",
21+
"comparison",
22+
"twox-hash-sum",
23+
"xx_hash-sys",
24+
]
25+
#END-[workspace]
26+
27+
[features]
28+
default = ["random", "xxhash32", "xxhash64", "xxhash3_64", "std"]
29+
30+
random = ["dep:rand"]
31+
32+
serialize = ["dep:serde"]
33+
34+
xxhash32 = []
35+
xxhash64 = []
36+
xxhash3_64 = []
37+
38+
std = ["alloc"]
39+
alloc = []
40+
41+
[lints.rust.unexpected_cfgs]
42+
level = "warn"
43+
check-cfg = [
44+
'cfg(_internal_xxhash3_force_scalar)',
45+
'cfg(_internal_xxhash3_force_neon)',
46+
'cfg(_internal_xxhash3_force_sse2)',
47+
'cfg(_internal_xxhash3_force_avx2)',
48+
]
49+
1750
[dependencies]
18-
cfg-if = { version = ">= 0.1, < 2", default-features = false }
19-
static_assertions = { version = "1.0", default-features = false }
20-
rand = { version = ">= 0.3.10, < 0.9", optional = true }
21-
serde = { version = "1.0", features = ["derive"], optional = true}
22-
digest = { package = "digest", version = "0.8", default-features = false, optional = true }
23-
digest_0_9 = { package = "digest", version = "0.9", default-features = false, optional = true }
24-
digest_0_10 = { package = "digest", version = "0.10", default-features = false, optional = true }
51+
rand = { version = "0.8.0", optional = true, default-features = false, features = ["std", "std_rng"] }
52+
serde = { version = "1.0.0", optional = true, default-features = false, features = ["derive"] }
2553

2654
[dev-dependencies]
27-
serde_json = "1.0"
55+
serde_json = "1.0.117"
56+
#END-[dev-dependencies]
2857

29-
[features]
30-
default = ["std"]
31-
serialize = ["serde"]
32-
std = ["rand"]
58+
[package.metadata.docs.rs]
59+
all-features = true

0 commit comments

Comments
 (0)