vortex_vector/null/
vector.rs1use std::fmt::Debug;
7use std::ops::BitAnd;
8use std::ops::RangeBounds;
9
10use vortex_mask::Mask;
11
12use crate::VectorOps;
13use crate::null::NullScalar;
14use crate::null::NullVectorMut;
15
16#[derive(Debug, Clone, Eq)]
23pub struct NullVector {
24 pub(super) len: usize,
26 pub(super) validity: Mask,
29}
30
31impl PartialEq for NullVector {
32 fn eq(&self, other: &Self) -> bool {
33 self.len == other.len
36 }
37}
38
39impl NullVector {
40 pub fn new(len: usize) -> Self {
42 Self {
43 len,
44 validity: Mask::AllFalse(len),
45 }
46 }
47}
48
49impl VectorOps for NullVector {
50 type Mutable = NullVectorMut;
51 type Scalar = NullScalar;
52
53 fn len(&self) -> usize {
54 self.len
55 }
56
57 fn validity(&self) -> &Mask {
58 &self.validity
59 }
60
61 fn mask_validity(&mut self, mask: &Mask) {
62 self.validity = self.validity.bitand(mask);
63 }
64
65 fn scalar_at(&self, index: usize) -> NullScalar {
66 assert!(index < self.len, "Index out of bounds in `NullVector`");
67 NullScalar
68 }
69
70 fn slice(&self, range: impl RangeBounds<usize> + Clone + Debug) -> Self {
71 let len = crate::vector_ops::range_bounds_to_len(range, self.len());
72 Self::new(len)
73 }
74
75 fn clear(&mut self) {
76 self.len = 0;
77 self.validity = Mask::AllFalse(0);
78 }
79
80 fn try_into_mut(self) -> Result<NullVectorMut, Self> {
81 Ok(NullVectorMut::new(self.len))
82 }
83
84 fn into_mut(self) -> NullVectorMut {
85 NullVectorMut::new(self.len)
86 }
87}