use crc32fast::Hasher;
pub fn crc(data: &[u8]) -> u32 {
let mut hasher = Hasher::new();
hasher.update(data);
let c = hasher.finalize();
c.rotate_right(15).wrapping_add(0xa282ead8)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_crc_empty() {
let result = crc(&[]);
assert_ne!(result, 0);
}
#[test]
fn test_crc_consistency() {
let data = b"Hello, World!";
let crc1 = crc(data);
let crc2 = crc(data);
assert_eq!(crc1, crc2, "CRC should be deterministic");
}
#[test]
fn test_crc_different_data() {
let data1 = b"Hello";
let data2 = b"World";
let crc1 = crc(data1);
let crc2 = crc(data2);
assert_ne!(crc1, crc2, "Different data should produce different CRCs");
}
}