Skip to content

Commit d8d91ca

Browse files
committed
add spare_capacity_mut to PVectorMut
Signed-off-by: Connor Tsui <[email protected]>
1 parent c4240f1 commit d8d91ca

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

vortex-vector/src/primitive/generic_mut_impl.rs

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

44
//! Helper methods for [`PVectorMut<T>`] that mimic the behavior of [`std::vec::Vec`].
55
6+
use std::mem::MaybeUninit;
7+
68
use vortex_buffer::BufferMut;
79
use vortex_dtype::NativePType;
810

@@ -131,6 +133,24 @@ impl<T: NativePType> PVectorMut<T> {
131133
}
132134
}
133135
}
136+
137+
/// Returns the remaining spare capacity of the vector as a slice of [`MaybeUninit<T>`].
138+
///
139+
/// The returned slice can be used to fill the buffer with data before marking the data as
140+
/// initialized using unsafe methods like [`set_len`].
141+
///
142+
/// # Safety
143+
///
144+
/// Note that this only provides access to the spare capacity of the **elements** buffer.
145+
///
146+
/// After writing to the spare capacity and calling [`set_len`], the caller must also ensure the
147+
/// validity mask is updated accordingly to maintain consistency.
148+
///
149+
/// [`set_len`]: Self::set_len
150+
#[inline]
151+
pub unsafe fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>] {
152+
self.elements.spare_capacity_mut()
153+
}
134154
}
135155

136156
#[cfg(test)]

0 commit comments

Comments
 (0)