Struct rolling_dual_crc::RollingDualCrc [−][src]
pub struct RollingDualCrc { /* fields omitted */ }
Expand description
Computes 32-bit CRC-32C
and 64-bit CRC-64/XZ
checksums
in a rolling window that moves through the input data.
Examples
Compute checksums of 3-byte windows of "abcde"
,
i.e. "abc"
, "bcd"
and "cde"
.
use rolling_dual_crc::RollingDualCrc;
let mut crc = RollingDualCrc::new("abc");
// checksum of "abc"
assert_eq!(crc.get32(), 0x364B3FB7);
crc.roll(b'd');
// checksum of "bcd"
assert_eq!(crc.get32(), 0x1B0D0358);
crc.roll(b'e');
// checksum of "cde"
assert_eq!(crc.get32(), 0x364ADB60);
Implementations
Returns 32-bit CRC-32C
and 64-bit CRC-64/XZ
checksums
of the current window.
Examples
use rolling_dual_crc::RollingDualCrc;
let mut crc = RollingDualCrc::new("abc");
crc.roll(b'd');
// checksums of "bcd"
assert_eq!(crc.get(), (0x1B0D0358, 0x0557EA6AA1219070));
Returns 32-bit CRC-32C
checksum of the current window.
Examples
use rolling_dual_crc::RollingDualCrc;
let mut crc = RollingDualCrc::new("abc");
crc.roll(b'd');
// checksum of "bcd"
assert_eq!(crc.get32(), 0x1B0D0358);
Returns 64-bit CRC-64/XZ
checksum of the current window.
Examples
use rolling_dual_crc::RollingDualCrc;
let mut crc = RollingDualCrc::new("abc");
crc.roll(b'd');
// checksum of "bcd"
assert_eq!(crc.get64(), 0x0557EA6AA1219070);
Begins computation of 32-bit CRC-32C
and 64-bit CRC-64/XZ
rolling checksums.
- Sets
window_size
to size of the given initial window. (window_size
remains same during rolling.) - Allocates and initializes buffer of
window_size
bytes for the window contents. - Allocates and initializes local lookup tables (3 kiB total).
- Computes checksums of initial window.
Panics
Panics if initial_window
is empty.
Examples
use rolling_dual_crc::RollingDualCrc;
let mut crc = RollingDualCrc::new("abc");
// checksum of "abc"
assert_eq!(crc.get32(), 0x364B3FB7);
Rolls window forward one byte.
- Appends the given byte to the window.
- Removes first byte of the window.
- Recomputes checksums for the new window.
This is a fast constant time Θ(1)
operation
which doesn’t depend on the size of the window.
Examples
use rolling_dual_crc::RollingDualCrc;
let mut crc = RollingDualCrc::new("abc");
crc.roll(b'd');
// checksum of "bcd"
assert_eq!(crc.get32(), 0x1B0D0358);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for RollingDualCrc
impl Send for RollingDualCrc
impl Sync for RollingDualCrc
impl Unpin for RollingDualCrc
impl UnwindSafe for RollingDualCrc
Blanket Implementations
Mutably borrows from an owned value. Read more