gecko-dev/third_party/rust/crc
Andreas Tolfsen f23e8c7f0e Bug 1439329 - Bump crate dependencies for zip 0.3. r=jgraham
Output from "./mach vendor rust":

	% ./mach vendor rust
	 0:01.15 rm -rf /Users/ato/src/gecko/third_party/rust
	      Adding adler32 v1.0.2
	      Adding build_const v0.2.0
	      Adding bzip2 v0.3.2
	      Adding bzip2-sys v0.1.6
	      Adding cc v1.0.4
	      Adding crc v1.7.0
	      Adding flate2 v1.0.1
	      Adding miniz_oxide v0.1.2
	      Adding miniz_oxide_c_api v0.1.2

MozReview-Commit-ID: EBVi4OdzYm3

--HG--
extra : rebase_source : b2f756574ebabc96b1378713a7ee6247274a388e
2018-02-19 12:33:08 +01:00
..
benches
src
tests
.cargo-checksum.json
.travis.yml
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
build.rs

README.md

crc Build Status

Rust implementation of CRC(32, 64) with support of various standards

Usage

Add crc to Cargo.toml

[dependencies]
crc = "^1.0.0"

or

[dependencies.crc]
git = "https://github.com/mrhooray/crc-rs"

Add this to crate root

extern crate crc;

Compute CRC32

use crc::{crc32, Hasher32};

// CRC-32-IEEE being the most commonly used one
assert_eq!(crc32::checksum_ieee(b"123456789"), 0xcbf43926);
assert_eq!(crc32::checksum_castagnoli(b"123456789"), 0xe3069283);
assert_eq!(crc32::checksum_koopman(b"123456789"), 0x2d3dd0ae);

// use provided or custom polynomial
let mut digest = crc32::Digest::new(crc32::IEEE);
digest.write(b"123456789");
assert_eq!(digest.sum32(), 0xcbf43926);

// with initial
let mut digest = crc32::Digest::new_with_initial(crc32::IEEE, 0u32);
digest.write(b"123456789");
assert_eq!(digest.sum32(), 0xcbf43926);

Compute CRC64

use crc::{crc64, Hasher64};

assert_eq!(crc64::checksum_ecma(b"123456789"), 0x995dc9bbdf1939fa);
assert_eq!(crc64::checksum_iso(b"123456789"), 0xb90956c775a41001);

// use provided or custom polynomial
let mut digest = crc64::Digest::new(crc64::ECMA);
digest.write(b"123456789");
assert_eq!(digest.sum64(), 0x995dc9bbdf1939fa);

// with initial
let mut digest = crc64::Digest::new_with_initial(crc64::ECMA, 0u64);
digest.write(b"123456789");
assert_eq!(digest.sum64(), 0x995dc9bbdf1939fa);

Benchmark

Bencher is currently not available in Rust stable releases.

cargo bench with 2.3 GHz Intel Core i7 results ~430MB/s throughput. Comparison

cargo bench
     Running target/release/bench-5c82e94dab3e9c79

running 4 tests
test bench_crc32_make_table       ... bench:       439 ns/iter (+/- 82)
test bench_crc32_update_megabytes ... bench:   2327803 ns/iter (+/- 138845)
test bench_crc64_make_table       ... bench:      1200 ns/iter (+/- 223)
test bench_crc64_update_megabytes ... bench:   2322472 ns/iter (+/- 92870)

test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.