#[derive(Clone, Default, Debug)]
pub struct BkdrsubDelimiter {
delimiter: u8,
}
impl BkdrsubDelimiter {
pub fn from(delimiter: u8) -> Self {
Self { delimiter }
}
}
impl super::Hash for BkdrsubDelimiter {
fn hash<S: super::HashKey>(&self, key: &S) -> i64 {
const SEED: i32 = 131; const START_CHAR_VAL: u8 = '#' as u8;
let end_char_val: u8 = self.delimiter;
let mut hash = 0_i32;
let mut found_start_char = false;
for i in 0..key.len() {
let c = key.at(i);
if found_start_char {
if c != end_char_val {
hash = hash.wrapping_mul(SEED).wrapping_add(c as i32);
continue;
}
break;
} else if c == START_CHAR_VAL {
found_start_char = true;
continue;
}
}
hash = hash & 0x7FFFFFFF;
hash as i64
}
}