Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions vortex-vector/src/binaryview/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ impl<T: BinaryViewType> VectorMutOps for BinaryViewVectorMut<T> {
self.views.len()
}

fn validity(&self) -> &MaskMut {
&self.validity
}

fn capacity(&self) -> usize {
self.views.capacity()
}
Expand Down
4 changes: 4 additions & 0 deletions vortex-vector/src/bool/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ impl VectorMutOps for BoolVectorMut {
self.bits.len()
}

fn validity(&self) -> &MaskMut {
&self.validity
}

fn capacity(&self) -> usize {
self.bits.capacity()
}
Expand Down
4 changes: 4 additions & 0 deletions vortex-vector/src/decimal/generic_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ impl<D: NativeDecimalType> VectorMutOps for DVectorMut<D> {
self.elements.len()
}

fn validity(&self) -> &MaskMut {
&self.validity
}

fn capacity(&self) -> usize {
self.elements.capacity()
}
Expand Down
5 changes: 5 additions & 0 deletions vortex-vector/src/decimal/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use vortex_dtype::{
DecimalDType, DecimalType, DecimalTypeDowncast, DecimalTypeUpcast, NativeDecimalType, i256,
};
use vortex_error::vortex_panic;
use vortex_mask::MaskMut;

use crate::decimal::{DVectorMut, DecimalVector};
use crate::{VectorMutOps, match_each_dvector_mut};
Expand Down Expand Up @@ -63,6 +64,10 @@ impl VectorMutOps for DecimalVectorMut {
match_each_dvector_mut!(self, |d| { d.len() })
}

fn validity(&self) -> &MaskMut {
match_each_dvector_mut!(self, |d| { d.validity() })
}

fn capacity(&self) -> usize {
match_each_dvector_mut!(self, |d| { d.capacity() })
}
Expand Down
4 changes: 4 additions & 0 deletions vortex-vector/src/fixed_size_list/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ impl VectorMutOps for FixedSizeListVectorMut {
self.len
}

fn validity(&self) -> &MaskMut {
&self.validity
}

/// In the case that `list_size == 0`, the capacity of the vector is infinite because it will
/// never take up any space.
fn capacity(&self) -> usize {
Expand Down
21 changes: 18 additions & 3 deletions vortex-vector/src/null/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! Definition and implementation of [`NullVectorMut`].

use vortex_mask::MaskMut;

use crate::VectorMutOps;
use crate::null::NullVector;

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

impl NullVectorMut {
/// Creates a new mutable vector of nulls with the given length.
pub fn new(len: usize) -> Self {
Self { len }
Self {
len,
validity: MaskMut::new_false(len),
}
}
}

Expand All @@ -32,6 +40,10 @@ impl VectorMutOps for NullVectorMut {
self.len
}

fn validity(&self) -> &MaskMut {
&self.validity
}

fn capacity(&self) -> usize {
usize::MAX
}
Expand Down Expand Up @@ -62,7 +74,10 @@ impl VectorMutOps for NullVectorMut {

let new_len = self.len.saturating_sub(at);
self.len = std::cmp::min(self.len, at);
NullVectorMut { len: new_len }
NullVectorMut {
len: new_len,
validity: MaskMut::new_false(new_len),
}
}

fn unsplit(&mut self, other: Self) {
Expand Down
9 changes: 8 additions & 1 deletion vortex-vector/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! Definition and implementation of [`VectorOps`] and [`VectorMutOps`] for [`Vector`] and
//! [`VectorMut`], respectively.

use vortex_mask::Mask;
use vortex_mask::{Mask, MaskMut};

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

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

/// Returns the validity mask of the vector, where `true` represents a _valid_ element and
/// `false` represents a `null` element.
///
/// Note that while this returns a [`MaskMut`] (which is typically an owned type), the caller is
/// only allowed to inspect it via the shared reference.
fn validity(&self) -> &MaskMut;

/// Returns the total number of elements the vector can hold without reallocating.
fn capacity(&self) -> usize;

Expand Down
4 changes: 4 additions & 0 deletions vortex-vector/src/primitive/generic_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl<T: NativePType> VectorMutOps for PVectorMut<T> {
self.elements.len()
}

fn validity(&self) -> &MaskMut {
&self.validity
}

fn capacity(&self) -> usize {
self.elements.capacity()
}
Expand Down
7 changes: 0 additions & 7 deletions vortex-vector/src/primitive/generic_mut_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use vortex_buffer::BufferMut;
use vortex_dtype::NativePType;
use vortex_mask::MaskMut;

use crate::VectorMutOps;
use crate::primitive::PVectorMut;
Expand Down Expand Up @@ -106,12 +105,6 @@ impl<T: NativePType> PVectorMut<T> {
&self.elements
}

/// Returns the validity of the [`PVectorMut`].
#[inline]
pub fn validity(&self) -> &MaskMut {
&self.validity
}

/// Resizes the `Vec` in-place so that `len` is equal to `new_len`.
///
/// If `new_len` is greater than `len`, the `Vec` is extended by the difference, with each
Expand Down
5 changes: 5 additions & 0 deletions vortex-vector/src/primitive/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use vortex_dtype::half::f16;
use vortex_dtype::{NativePType, PType, PTypeDowncast, PTypeUpcast};
use vortex_error::vortex_panic;
use vortex_mask::MaskMut;

use crate::primitive::{PVectorMut, PrimitiveVector};
use crate::{VectorMutOps, match_each_pvector_mut};
Expand Down Expand Up @@ -87,6 +88,10 @@ impl VectorMutOps for PrimitiveVectorMut {
match_each_pvector_mut!(self, |v| { v.len() })
}

fn validity(&self) -> &MaskMut {
match_each_pvector_mut!(self, |v| { v.validity() })
}

fn capacity(&self) -> usize {
match_each_pvector_mut!(self, |v| { v.capacity() })
}
Expand Down
4 changes: 4 additions & 0 deletions vortex-vector/src/struct_/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl VectorMutOps for StructVectorMut {
self.len
}

fn validity(&self) -> &MaskMut {
&self.validity
}

fn capacity(&self) -> usize {
self.minimum_capacity()
}
Expand Down
5 changes: 5 additions & 0 deletions vortex-vector/src/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use vortex_dtype::DType;
use vortex_error::vortex_panic;
use vortex_mask::MaskMut;

use crate::binaryview::{BinaryVectorMut, StringVectorMut};
use crate::bool::BoolVectorMut;
Expand Down Expand Up @@ -90,6 +91,10 @@ impl VectorMutOps for VectorMut {
match_each_vector_mut!(self, |v| { v.len() })
}

fn validity(&self) -> &MaskMut {
match_each_vector_mut!(self, |v| { v.validity() })
}

fn capacity(&self) -> usize {
match_each_vector_mut!(self, |v| { v.capacity() })
}
Expand Down
Loading