Skip to content

Commit 35a2f83

Browse files
committed
crc-fast-rust: doc clean
1 parent 70c5006 commit 35a2f83

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/combine.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
//! This module provides a function to combine CRCs of two sequences of bytes.
1+
//! CRC Combination Module
22
//!
3-
//! It is based on the work of Mark Adler and is designed to be used with
4-
//! different CRC algorithms.
3+
//! This module provides functionality to combine two CRC checksums into a single CRC
4+
//! value that represents the concatenated data sequence. This is useful for:
5+
//!
6+
//! - **Distributed computing**: Calculate CRCs on different chunks in parallel, then combine
7+
//! - **Incremental updates**: Append new data without recalculating the entire checksum
8+
//! - **Merkle-tree-like structures**: Build hierarchical CRC structures
9+
//!
10+
//! # Algorithm
11+
//!
12+
//! Based on Mark Adler's generalized CRC combination algorithm, which uses Galois Field (GF(2))
13+
//! matrix operations to efficiently "insert" zeros between two checksums. The key insight is
14+
//! that CRC can be viewed as polynomial multiplication in GF(2), and appending zeros is
15+
//! equivalent to multiplying by x^n (where n is the number of zeros).
16+
//!
17+
//! # Performance
18+
//!
19+
//! The combination operation runs in O(log N) time where N is the length of the second
20+
//! sequence, achieved through matrix squaring to efficiently compute the zero-insertion operator.
21+
//!
22+
//! # References
23+
//!
24+
//! - [Mark Adler's StackOverflow answer](https://stackoverflow.com/questions/29915764/generic-crc-8-16-32-64-combine-implementation/29928573#29928573)
25+
//! - [Ross Williams' CRC tutorial](http://www.ross.net/crc/download/crc_v3.txt)
526
/*
627
Derived from this excellent answer by Mark Adler on StackOverflow:
728
https://stackoverflow.com/questions/29915764/generic-crc-8-16-32-64-combine-implementation/29928573#29928573
@@ -175,14 +196,6 @@ fn reflect_poly(poly: u64, width: u32) -> u64 {
175196
shifted & mask
176197
}
177198

178-
fn bit_reverse(mut forward: u64) -> u64 {
179-
let mut reversed = 0;
180-
181-
for _ in 0..64 {
182-
reversed <<= 1;
183-
reversed |= forward & 1;
184-
forward >>= 1;
185-
}
186-
187-
reversed
199+
fn bit_reverse(forward: u64) -> u64 {
200+
forward.reverse_bits()
188201
}

0 commit comments

Comments
 (0)