Add durandal::crc module

png-branch
an 2018-09-09 18:13:50 -04:00
parent f5984c9739
commit cba430393a
2 changed files with 21 additions and 2 deletions

18
src/durandal/crc.rs Normal file
View File

@ -0,0 +1,18 @@
fn crc_init() -> [u32; 256]
{
let mut t = [0; 256];
for n in 0..256
{
t[n] = (0..8).fold(n as u32, |a, _|
{if a & 1 == 1 {0xedb88320 ^ a >> 1} else {a >> 1}});
}
t
}
pub fn crc32(b: &[u8], s: u32) -> u32
{
let t = crc_init();
!b.iter().fold(s, |a, &o| {a >> 8 ^ t[(a & 0xff ^ o as u32) as usize]})
}
// EOF

View File

@ -2,9 +2,10 @@
#[allow(dead_code)]
pub mod bin;
pub mod machead;
pub mod text;
pub mod crc;
pub mod image;
pub mod machead;
pub mod pict;
pub mod text;
// EOF