use alloc::vec::Vec;
pub fn find_min_size(val: u64) -> usize {
if val == 0 {
return 1;
}
if val >> 8 == 0 {
return 1;
}
if val >> 16 == 0 {
return 2;
}
if val >> 32 == 0 {
return 4;
}
8
}
pub fn write_minified_val(val: u64, output: &mut Vec<u8>) {
let new_size = find_min_size(val);
output.extend_from_slice(&val.to_le_bytes()[0..new_size]);
}
pub fn find_fcs_field_size(val: u64, single_segment: bool) -> usize {
if single_segment && val <= 255 {
return 1;
}
if (256..=65791).contains(&val) {
return 2;
}
if val <= u32::MAX as u64 {
return 4;
}
8
}
#[cfg(not(target_pointer_width = "32"))]
#[inline(always)]
pub(crate) fn hash_top_bits(product: u64, width: u32) -> u32 {
debug_assert!(
(1..=32).contains(&width),
"hash width {width} out of 1..=32"
);
(product >> (64 - width)) as u32
}
#[cfg(target_pointer_width = "32")]
#[inline(always)]
pub(crate) fn hash_top_bits(product: u64, width: u32) -> u32 {
debug_assert!(
(1..=32).contains(&width),
"hash width {width} out of 1..=32"
);
((product >> 32) as u32) >> (32 - width)
}
#[cfg(test)]
mod tests;