A commutative hasher that supports parallel and out-of-order computation - #156
Open
bb8gh wants to merge 2 commits into
Open
A commutative hasher that supports parallel and out-of-order computation#156bb8gh wants to merge 2 commits into
bb8gh wants to merge 2 commits into
Conversation
This is useful in situations where a hash of a large file is needed, but the file is processed non-sequentially (such as blocks being downloaded in parallel). The hash can be built up in any order but still produce the same value for the same input data.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Block alignment is not fully enforced, and sequential offsets can overflow on 32-bit targets.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Balanced
Findings: 1
New issues introduced by this change (5)
| Severity | Finding |
|---|---|
crates/commutative_hasher/src/lib.rs — This cumulative offset can overflow on 32-bit targets after a sequential stream exceeds 4 GiB.… |
|
crates/commutative_hasher/src/lib.rs — The documented alignment contract is not enforced for data.len(). Any short slice is accepted at… |
|
crates/commutative_hasher/src/lib.rs — This 128 MiB hashing test runs in the default suite, despite the repository's explicit `make… |
|
crates/commutative_hasher/README.md — The subject is singular, so “always get” should be “always gets.” |
|
crates/commutative_hasher/README.md — This Rust example cannot compile: ... is not Rust syntax and no digest value is initialized… |
What changed in this PR
Adds a commutative, block-based Rust hasher supporting parallel and out-of-order processing.
Changes:
- Adds parallel/sequential hashers and digest serialization.
- Adds tests, documentation, and workspace integration.
- Adds optional serde support.
| File | Description |
|---|---|
README.md |
Lists the new crate. |
Makefile |
Tests serde support. |
crates/commutative_hasher/src/lib.rs |
Implements hashers, digests, and tests. |
crates/commutative_hasher/README.md |
Documents usage and behavior. |
crates/commutative_hasher/Cargo.toml |
Defines crate metadata and dependencies. |
Suppressed comments (1)
crates/commutative_hasher/src/lib.rs:542
- This parameterized test hashes and allocates 128 MiB six times in every default test run, and the serde command runs it all again. The repository routes expensive tests through
make test-ignored(Makefile:44-48); please mark this test ignored or use a much smaller multi-block fixture.
#[rstest]
fn test_hash_large_value_sequential(#[values(1, 2, 8, 10, 60, 200)] num_chunks: usize) {
let expected_digest = "ee7338897f6eaf9b4f26b6ec33d3192bca8231485ac70d64fc81128397af0755";
let data = generate_data(1 << 27); // 128 MiB
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This is useful in situations where a hash of a large file is needed, but the file is processed non-sequentially (such as blocks being downloaded in parallel). The hash can be built up in any order but still produce the same value for the same input data.