Skip to content

Commit

Permalink
Merge pull request #101 from shepmaster/v2
Browse files Browse the repository at this point in the history
Rewrite for version 2
  • Loading branch information
shepmaster authored Oct 18, 2024
2 parents 5f3f3a3 + 6d4ffd4 commit 872959e
Show file tree
Hide file tree
Showing 61 changed files with 6,911 additions and 4,036 deletions.
185 changes: 126 additions & 59 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,173 @@ on: push

name: Continuous integration

env:
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings

jobs:
library:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- ubuntu-latest

rust:
- stable
- beta
- nightly
- 1.37.0 # MSRV
- 1.81.0 # MSRV

include:
- platform: macos-latest # This serves as our aarch64 / arm64 runner
rust: stable

- platform: windows-latest
rust: stable

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions-rs/toolchain@v1
- run: git submodule update --init --recursive

- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy

- uses: actions-rs/cargo@v1
with:
command: build
- name: Unit Tests
run: cargo test --all-features

- uses: actions-rs/cargo@v1
with:
command: test
- name: Property Tests
run: cargo test -p comparison --all-features

- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
miri:
runs-on: ubuntu-latest
env:
MIRIFLAGS: --cfg _internal_xxhash3_force_scalar

steps:
- uses: actions/checkout@v4

- uses: actions-rs/cargo@v1
- uses: dtolnay/rust-toolchain@master
with:
command: fmt
args: --all -- --check
if: ${{ matrix.rust == 'stable' }}
toolchain: nightly
components: miri

- uses: actions-rs/cargo@v1
- name: Unsafe Code
run: cargo miri test --all-features

- name: Big Endian Platform
run: cargo miri test --all-features --target s390x-unknown-linux-gnu

lints:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- run: git submodule update --init --recursive

- uses: dtolnay/rust-toolchain@master
with:
command: clippy
args: --all-features -- -D warnings
if: ${{ matrix.rust == 'stable' }}
toolchain: stable
components: rustfmt, clippy

- run: cargo fmt --all

- run: cargo clippy --all --all-targets --all-features

- run: cargo doc --all-features

no-std:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: stable
target: thumbv6m-none-eabi
override: true
targets: thumbv6m-none-eabi

- uses: actions-rs/cargo@v1
with:
command: build
args: --no-default-features --target thumbv6m-none-eabi --lib
- run: >
cargo build
--no-default-features
--features=xxhash32,xxhash64,xxhash3_64
--target thumbv6m-none-eabi
compatibility-tests:
features:
runs-on: ubuntu-latest
strategy:
matrix:
test:
- digest_0_8
- digest_0_9

env:
IMPLEMENTATIONS: xxhash32 xxhash64 xxhash3_64
FEATURE_SET: random serialize std alloc

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- run: git submodule update --init --recursive

- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: stable
override: true

- uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path "compatibility-tests/${{ matrix.test }}/Cargo.toml"
- name: Compute Powerset
shell: "ruby {0}"
run: |
features = ENV['FEATURE_SET']
.split(' ')
.reduce([[]]) { |ps, i| ps + ps.map { |e| e + [i] } }
.map { |s| s.join(',') }
.join(" ")
File.open(ENV['GITHUB_ENV'], 'a') { |f| f.write("FEATURES=#{features}") }
big_endian:
- name: Check implementations with features
run: |
for impl in ${IMPLEMENTATIONS}; do
echo "::group::Implementation ${impl}"
# Check the implementation by itself
cargo check --no-default-features --features="${impl}"
# And with extra features
for feature in ${FEATURES}; do
echo "::group::Features ${feature}"
cargo check --no-default-features --features="${impl},${feature}"
echo "::endgroup::"
done
echo ::endgroup::
done
minimal-versions:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- run: git submodule update --init --recursive

- uses: dtolnay/rust-toolchain@master
with:
platforms: s390x
toolchain: 1.81.0 # MSRV

- name: Cross test
uses: actions-rs/cargo@v1
- uses: dtolnay/rust-toolchain@master
with:
use-cross: true
command: test
args: --target s390x-unknown-linux-gnu
toolchain: nightly

- name: Remove non-essential dependencies
run: |
# Remove workspace dependencies
sed -i '/\[workspace]/,/#END-\[workspace]/d' Cargo.toml
# Remove dev-dependencies
sed -i '/\[dev-dependencies]/,/#END-\[dev-dependencies]/d' Cargo.toml
- name: Downgrade to minimal dependencies
run: |
cargo +nightly -Z minimal-versions update
- run: cargo +1.81.0 build --all-features
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
target
Cargo.lock
/Cargo.lock
/target
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "comparison/xxHash"]
path = comparison/xxHash
url = https://github.com/Cyan4973/xxHash.git
[submodule "xxHash"]
path = xx_hash-sys/xxHash
url = https://github.com/Cyan4973/xxHash.git
85 changes: 85 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - Unreleased

[2.0.0]: https://github.com/shepmaster/twox-hash/tree/v2.0.0

This release is a complete rewrite of the crate, including
reorganization of the code. The XXH3 algorithm now matches the 0.8
release of the reference C xxHash implementation.

### Added

- `XxHash32::oneshot` and `XxHash64::oneshot` can perform hashing with
zero allocation and generally improved performance. If you have code
that creates a hasher and hashes a slice of bytes exactly once, you
are strongly encouraged to use the new functions. This might look
like:

```rust
// Before
let mut hasher = XxHash64::new(); // or XxHash32, or with seeds
some_bytes.hash(&mut hasher);
let hash = hasher.finish();

// After
let hash = XxHash64::oneshot(some_bytes);
```

- There is a feature flag for each hashing implementation. It is
recommended that you opt-out of the crate's default features and
only select the implementations you need to improve compile speed.

### Changed

- The crates minimum supported Rust version (MSRV) is now 1.81.

- Functional and performance comparisons are made against the
reference C xxHash library version 0.8.2, which includes a stable
XXH3 algorithm.

- Support for randomly-generated hasher instances is now behind the
`random` feature flag. It was previously combined with the `std`
feature flag.

### Removed

- The deprecated type aliases `XxHash` and `RandomXxHashBuilder` have
been removed. Replace them with `XxHash64` and
`xxhash64::RandomState` respectively.

- `RandomXxHashBuilder32` and `RandomXxHashBuilder64` are no longer
available at the top-level of the crate. Replace them with
`xxhash32::RandomState` and ``xxhash64::RandomState` respectively.

- `Xxh3Hash64` and `xx3::Hash64` have been renamed to `XxHash3_64` and
`xxhash3_64::Hasher` respectively.

- The free functions `xxh3::hash64`, `xxh3::hash64_with_seed`, and
`xxh3::hash64_with_secret` are now associated functions of
`xxhash3_64::Hasher`: `oneshot`, `oneshot_with_seed` and
`oneshot_with_secret`. Note that the argument order has changed.

- Support for the [digest][] crate has been removed. The digest crate
is for **cryptographic** hash functions and xxHash is
**non-cryptographic**.

- `XxHash32` and `XxHash64` no longer implement `Copy`. This prevents
accidentally mutating a duplicate instance of the state instead of
the original state. `Clone` is still implemented so you can make
deliberate duplicates.

- The XXH3 128-bit variant is not yet re-written. Work is in progress
for this.

- We no longer provide support for randomly-generated instances of the
XXH3 64-bit variant. The XXH3 algorithm takes both a seed and a
secret as input and deciding what to randomize is non-trivial and
can have negative impacts on performance.

[digest]: https://docs.rs/digest/latest/digest/
53 changes: 40 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "twox-hash"
version = "1.6.3"
authors = ["Jake Goulding <[email protected]>"]
edition = "2018"
edition = "2021"
rust-version = "1.81"

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

license = "MIT"

[workspace]
members = [
"asmasm",
"comparison",
"twox-hash-sum",
"xx_hash-sys",
]
#END-[workspace]

[features]
default = ["random", "xxhash32", "xxhash64", "xxhash3_64", "std"]

random = ["dep:rand"]

serialize = ["dep:serde"]

xxhash32 = []
xxhash64 = []
xxhash3_64 = []

std = ["alloc"]
alloc = []

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(_internal_xxhash3_force_scalar)',
'cfg(_internal_xxhash3_force_neon)',
'cfg(_internal_xxhash3_force_sse2)',
'cfg(_internal_xxhash3_force_avx2)',
]

[dependencies]
cfg-if = { version = ">= 0.1, < 2", default-features = false }
static_assertions = { version = "1.0", default-features = false }
rand = { version = ">= 0.3.10, < 0.9", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true}
digest = { package = "digest", version = "0.8", default-features = false, optional = true }
digest_0_9 = { package = "digest", version = "0.9", default-features = false, optional = true }
digest_0_10 = { package = "digest", version = "0.10", default-features = false, optional = true }
rand = { version = "0.8.0", optional = true, default-features = false, features = ["std", "std_rng"] }
serde = { version = "1.0.0", optional = true, default-features = false, features = ["derive"] }

[dev-dependencies]
serde_json = "1.0"
serde_json = "1.0.117"
#END-[dev-dependencies]

[features]
default = ["std"]
serialize = ["serde"]
std = ["rand"]
[package.metadata.docs.rs]
all-features = true
Loading

0 comments on commit 872959e

Please sign in to comment.