pub mod alp;
pub mod alp_rd;
pub mod bitpack;
pub mod bool_bitpack;
mod counts;
pub mod delta;
pub mod delta_patch;
pub mod dict;
pub mod for_bitpack;
pub mod frequency;
pub mod fsst;
pub mod patch;
pub mod rle;
pub mod segment;
pub mod validity;
pub mod zstd_leaf;
use zu_common::ZuError;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
#[repr(u8)]
pub enum EncodingId {
Plain = 0,
Constant = 1,
Rle = 2,
Dict = 3,
ForBitPack = 4,
DeltaBitPack = 5,
Alp = 6,
AlpRd = 7,
Fsst = 8,
BoolBitpack = 9,
Frequency = 10,
Zstd = 11,
DeltaPatch = 12,
}
impl TryFrom<u8> for EncodingId {
type Error = ZuError;
fn try_from(v: u8) -> Result<Self, ZuError> {
Ok(match v {
0 => Self::Plain,
1 => Self::Constant,
2 => Self::Rle,
3 => Self::Dict,
4 => Self::ForBitPack,
5 => Self::DeltaBitPack,
6 => Self::Alp,
7 => Self::AlpRd,
8 => Self::Fsst,
9 => Self::BoolBitpack,
10 => Self::Frequency,
11 => Self::Zstd,
12 => Self::DeltaPatch,
other => {
return Err(ZuError::Unsupported {
what: "encoding",
id: u32::from(other),
});
}
})
}
}
#[inline]
pub fn bits_needed(max: u64) -> u32 {
64 - max.leading_zeros()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn encoding_id_roundtrip() {
for raw in 0u8..=12 {
let id = EncodingId::try_from(raw).unwrap();
assert_eq!(id as u8, raw);
}
assert!(EncodingId::try_from(13).is_err());
}
#[test]
fn bits() {
assert_eq!(bits_needed(0), 0);
assert_eq!(bits_needed(1), 1);
assert_eq!(bits_needed(255), 8);
assert_eq!(bits_needed(256), 9);
assert_eq!(bits_needed(u64::MAX), 64);
}
}