Skip to content

Commit 99372f0

Browse files
committed
add immutable validity for mutable vectors
Signed-off-by: Connor Tsui <[email protected]>
1 parent d2272a3 commit 99372f0

File tree

12 files changed

+65
-11
lines changed

12 files changed

+65
-11
lines changed

vortex-vector/src/binaryview/vector_mut.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ impl<T: BinaryViewType> VectorMutOps for BinaryViewVectorMut<T> {
158158
self.views.len()
159159
}
160160

161+
fn validity(&self) -> &MaskMut {
162+
&self.validity
163+
}
164+
161165
fn capacity(&self) -> usize {
162166
self.views.capacity()
163167
}

vortex-vector/src/bool/vector_mut.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ impl VectorMutOps for BoolVectorMut {
8484
self.bits.len()
8585
}
8686

87+
fn validity(&self) -> &MaskMut {
88+
&self.validity
89+
}
90+
8791
fn capacity(&self) -> usize {
8892
self.bits.capacity()
8993
}

vortex-vector/src/decimal/generic_mut.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ impl<D: NativeDecimalType> VectorMutOps for DVectorMut<D> {
192192
self.elements.len()
193193
}
194194

195+
fn validity(&self) -> &MaskMut {
196+
&self.validity
197+
}
198+
195199
fn capacity(&self) -> usize {
196200
self.elements.capacity()
197201
}

vortex-vector/src/decimal/vector_mut.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use vortex_dtype::{
77
DecimalDType, DecimalType, DecimalTypeDowncast, DecimalTypeUpcast, NativeDecimalType, i256,
88
};
99
use vortex_error::vortex_panic;
10+
use vortex_mask::MaskMut;
1011

1112
use crate::decimal::{DVectorMut, DecimalVector};
1213
use crate::{VectorMutOps, match_each_dvector_mut};
@@ -63,6 +64,10 @@ impl VectorMutOps for DecimalVectorMut {
6364
match_each_dvector_mut!(self, |d| { d.len() })
6465
}
6566

67+
fn validity(&self) -> &MaskMut {
68+
match_each_dvector_mut!(self, |d| { d.validity() })
69+
}
70+
6671
fn capacity(&self) -> usize {
6772
match_each_dvector_mut!(self, |d| { d.capacity() })
6873
}

vortex-vector/src/fixed_size_list/vector_mut.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ impl VectorMutOps for FixedSizeListVectorMut {
172172
self.len
173173
}
174174

175+
fn validity(&self) -> &MaskMut {
176+
&self.validity
177+
}
178+
175179
/// In the case that `list_size == 0`, the capacity of the vector is infinite because it will
176180
/// never take up any space.
177181
fn capacity(&self) -> usize {

vortex-vector/src/null/vector_mut.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
//! Definition and implementation of [`NullVectorMut`].
55
6+
use vortex_mask::MaskMut;
7+
68
use crate::VectorMutOps;
79
use crate::null::NullVector;
810

@@ -12,16 +14,22 @@ use crate::null::NullVector;
1214
/// single `length` counter.
1315
///
1416
/// The immutable equivalent of this type is [`NullVector`].
15-
#[derive(Debug, Clone, Copy)]
17+
#[derive(Debug, Clone)]
1618
pub struct NullVectorMut {
1719
/// The total number of nulls.
1820
pub(super) len: usize,
21+
/// The validity mask. We only store this in order to implement the
22+
/// [`validity()`](Self::validity) method.
23+
pub(super) validity: MaskMut,
1924
}
2025

2126
impl NullVectorMut {
2227
/// Creates a new mutable vector of nulls with the given length.
2328
pub fn new(len: usize) -> Self {
24-
Self { len }
29+
Self {
30+
len,
31+
validity: MaskMut::new_false(len),
32+
}
2533
}
2634
}
2735

@@ -32,6 +40,10 @@ impl VectorMutOps for NullVectorMut {
3240
self.len
3341
}
3442

43+
fn validity(&self) -> &MaskMut {
44+
&self.validity
45+
}
46+
3547
fn capacity(&self) -> usize {
3648
usize::MAX
3749
}
@@ -62,7 +74,10 @@ impl VectorMutOps for NullVectorMut {
6274

6375
let new_len = self.len.saturating_sub(at);
6476
self.len = std::cmp::min(self.len, at);
65-
NullVectorMut { len: new_len }
77+
NullVectorMut {
78+
len: new_len,
79+
validity: MaskMut::new_false(new_len),
80+
}
6681
}
6782

6883
fn unsplit(&mut self, other: Self) {

vortex-vector/src/ops.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Definition and implementation of [`VectorOps`] and [`VectorMutOps`] for [`Vector`] and
55
//! [`VectorMut`], respectively.
66
7-
use vortex_mask::Mask;
7+
use vortex_mask::{Mask, MaskMut};
88

99
use crate::{Vector, VectorMut, private};
1010

@@ -56,6 +56,13 @@ pub trait VectorMutOps: private::Sealed + Into<VectorMut> {
5656
self.len() == 0
5757
}
5858

59+
/// Returns the validity mask of the vector, where `true` represents a _valid_ element and
60+
/// `false` represents a `null` element.
61+
///
62+
/// Note that while this returns an owned [`MaskMut`], the caller is only allowed to inspect it
63+
/// via the shared reference.
64+
fn validity(&self) -> &MaskMut;
65+
5966
/// Returns the total number of elements the vector can hold without reallocating.
6067
fn capacity(&self) -> usize;
6168

vortex-vector/src/primitive/generic_mut.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ impl<T: NativePType> VectorMutOps for PVectorMut<T> {
8686
self.elements.len()
8787
}
8888

89+
fn validity(&self) -> &MaskMut {
90+
&self.validity
91+
}
92+
8993
fn capacity(&self) -> usize {
9094
self.elements.capacity()
9195
}

vortex-vector/src/primitive/generic_mut_impl.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
use vortex_buffer::BufferMut;
77
use vortex_dtype::NativePType;
8-
use vortex_mask::MaskMut;
98

109
use crate::VectorMutOps;
1110
use crate::primitive::PVectorMut;
@@ -106,12 +105,6 @@ impl<T: NativePType> PVectorMut<T> {
106105
&self.elements
107106
}
108107

109-
/// Returns the validity of the [`PVectorMut`].
110-
#[inline]
111-
pub fn validity(&self) -> &MaskMut {
112-
&self.validity
113-
}
114-
115108
/// Resizes the `Vec` in-place so that `len` is equal to `new_len`.
116109
///
117110
/// If `new_len` is greater than `len`, the `Vec` is extended by the difference, with each

vortex-vector/src/primitive/vector_mut.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use vortex_dtype::half::f16;
77
use vortex_dtype::{NativePType, PType, PTypeDowncast, PTypeUpcast};
88
use vortex_error::vortex_panic;
9+
use vortex_mask::MaskMut;
910

1011
use crate::primitive::{PVectorMut, PrimitiveVector};
1112
use crate::{VectorMutOps, match_each_pvector_mut};
@@ -87,6 +88,10 @@ impl VectorMutOps for PrimitiveVectorMut {
8788
match_each_pvector_mut!(self, |v| { v.len() })
8889
}
8990

91+
fn validity(&self) -> &MaskMut {
92+
match_each_pvector_mut!(self, |v| { v.validity() })
93+
}
94+
9095
fn capacity(&self) -> usize {
9196
match_each_pvector_mut!(self, |v| { v.capacity() })
9297
}

0 commit comments

Comments
 (0)