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);

Rolls window forward.

This is equivalent to calling roll for each byte of the given slice.

Examples
use rolling_dual_crc::RollingDualCrc;

let mut crc = RollingDualCrc::new("abc");
crc.roll_slice("de");
// checksum of "cde"
assert_eq!(crc.get32(), 0x364ADB60);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.