use super::block::Block;
#[derive(Debug)]
pub struct BlockScanState {
pub row_pointers: Vec<*const u8>,
}
unsafe impl Send for BlockScanState {}
unsafe impl Sync for BlockScanState {}
impl BlockScanState {
pub const fn empty() -> Self {
BlockScanState {
row_pointers: Vec::new(),
}
}
pub fn clear(&mut self) {
self.row_pointers.clear();
}
pub fn row_pointers_iter(&self) -> impl Iterator<Item = *const u8> + Clone + '_ {
self.row_pointers.iter().copied()
}
pub(crate) unsafe fn prepare_block_scan(
&mut self,
block: &Block,
row_width: usize,
selection: impl IntoIterator<Item = usize>,
clear: bool,
) {
if clear {
self.row_pointers.clear();
}
let block_ptr = block.as_ptr();
for sel_idx in selection {
debug_assert!(sel_idx < block.num_rows(row_width));
let ptr = unsafe { block_ptr.byte_add(row_width * sel_idx) };
debug_assert!(block.data.contains_addr(ptr.addr()));
self.row_pointers.push(ptr);
}
}
}