use super::{Crc32local, Hash};
#[derive(Clone, Debug)]
pub struct Rawcrc32local {
crc32local: Crc32local,
}
impl Default for Rawcrc32local {
fn default() -> Self {
Rawcrc32local {
crc32local: Crc32local::default(),
}
}
}
const DELIMITER_UNDERSCORE: u8 = '_' as u8;
impl Hash for Rawcrc32local {
fn hash<S: super::HashKey>(&self, key: &S) -> i64 {
let mut hash = 0;
for i in 0..key.len() {
let c = key.at(i);
if !c.is_ascii_digit() {
if c == DELIMITER_UNDERSCORE {
return hash;
} else {
hash = 0;
break;
}
}
hash = hash.wrapping_mul(10) + (key.at(i) - '0' as u8) as i64;
}
if hash == 0 {
return self.crc32local.hash(key);
} else if hash > 0 {
return hash;
} else {
tracing::error!("found malform rawcrc32local for key: {:?}", key);
return 0;
}
}
}