1use crate::sel::SelVector;
8use crate::vector::ValueVector;
9
10pub struct DataChunk {
11 pub vecs: Vec<ValueVector>,
12 pub sel: Option<SelVector>,
15 pub count: u32,
17 pub cur: Option<u32>,
20}
21
22impl DataChunk {
23 pub fn new(vecs: Vec<ValueVector>, count: u32) -> Self {
24 Self {
25 vecs,
26 sel: None,
27 count,
28 cur: None,
29 }
30 }
31
32 pub fn active_count(&self) -> usize {
34 if self.cur.is_some() {
35 return 1;
36 }
37 match &self.sel {
38 Some(sel) => sel.len(),
39 None => self.count as usize,
40 }
41 }
42}
43
44pub struct ChunkSet {
47 pub chunks: Vec<DataChunk>,
48}
49
50impl ChunkSet {
51 pub fn new(chunks: Vec<DataChunk>) -> Self {
52 Self { chunks }
53 }
54
55 pub fn multiplicity(&self) -> u64 {
58 self.chunks
59 .iter()
60 .map(|c| c.active_count() as u64)
61 .product()
62 }
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68 use crate::arena::MorselArena;
69 use crate::vector::{PhysType, ValueVector};
70
71 #[test]
72 fn multiplicity_is_product_of_levels() {
73 let mut arena = MorselArena::new();
74 let flat = DataChunk::new(
75 vec![ValueVector::flat_from(
76 &mut arena,
77 PhysType::Int64,
78 &[1i64, 2],
79 )],
80 2,
81 );
82 let unflat = DataChunk::new(
83 vec![ValueVector::flat_from(
84 &mut arena,
85 PhysType::Int64,
86 &[10i64, 20, 30],
87 )],
88 3,
89 );
90 let set = ChunkSet::new(vec![flat, unflat]);
91 assert_eq!(set.multiplicity(), 6);
92 let mut pinned = set;
93 pinned.chunks[1].cur = Some(1);
94 assert_eq!(pinned.multiplicity(), 2);
95 }
96}