murr 0.2.0-rc2

Columnar in-memory cache for AI/ML inference workloads
Documentation
use crate::io::schema::{SegmentColumnSchema, SegmentSchema};

pub struct ReadRow<'a> {
    pub schema: &'a SegmentSchema,
    pub bitset: &'a [u8],
    pub values: &'a [u8],
}

impl<'a> ReadRow<'a> {
    pub fn new(schema: &'a SegmentSchema, raw: &'a [u8]) -> Self {
        let (bitset, values) = raw.split_at(schema.bitset_size);
        Self {
            schema,
            bitset,
            values,
        }
    }

    pub fn is_null(&self, column: &SegmentColumnSchema) -> bool {
        let idx = column.index as usize;
        let byte = idx / 8;
        let bit = (idx % 8) as u8;
        (self.bitset[byte] >> bit) & 1 == 1
    }

    pub fn read_static<T: bytemuck::Pod>(&self, column: &SegmentColumnSchema) -> T {
        let start = column.offset as usize;
        let end = start + std::mem::size_of::<T>();
        bytemuck::pod_read_unaligned(&self.values[start..end])
    }

    pub fn read_dynamic(&self, column: &SegmentColumnSchema) -> &[u8] {
        let slot = column.offset as usize;
        let payload_off =
            u32::from_le_bytes(self.values[slot..slot + 4].try_into().unwrap()) as usize;
        let len = u32::from_le_bytes(
            self.values[payload_off..payload_off + 4]
                .try_into()
                .unwrap(),
        ) as usize;
        &self.values[payload_off + 4..payload_off + 4 + len]
    }
}