use crate::sel::SelVector;
use crate::vector::ValueVector;
pub struct DataChunk {
pub vecs: Vec<ValueVector>,
pub sel: Option<SelVector>,
pub count: u32,
pub cur: Option<u32>,
}
impl DataChunk {
pub fn new(vecs: Vec<ValueVector>, count: u32) -> Self {
Self {
vecs,
sel: None,
count,
cur: None,
}
}
pub fn active_count(&self) -> usize {
if self.cur.is_some() {
return 1;
}
match &self.sel {
Some(sel) => sel.len(),
None => self.count as usize,
}
}
}
pub struct ChunkSet {
pub chunks: Vec<DataChunk>,
}
impl ChunkSet {
pub fn new(chunks: Vec<DataChunk>) -> Self {
Self { chunks }
}
pub fn multiplicity(&self) -> u64 {
self.chunks
.iter()
.map(|c| c.active_count() as u64)
.product()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::arena::MorselArena;
use crate::vector::{PhysType, ValueVector};
#[test]
fn multiplicity_is_product_of_levels() {
let mut arena = MorselArena::new();
let flat = DataChunk::new(
vec![ValueVector::flat_from(
&mut arena,
PhysType::Int64,
&[1i64, 2],
)],
2,
);
let unflat = DataChunk::new(
vec![ValueVector::flat_from(
&mut arena,
PhysType::Int64,
&[10i64, 20, 30],
)],
3,
);
let set = ChunkSet::new(vec![flat, unflat]);
assert_eq!(set.multiplicity(), 6);
let mut pinned = set;
pinned.chunks[1].cur = Some(1);
assert_eq!(pinned.multiplicity(), 2);
}
}