Skip to content

Commit 3eeee04

Browse files
committed
Vector::clear
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 50ddc86 commit 3eeee04

File tree

13 files changed

+68
-0
lines changed

13 files changed

+68
-0
lines changed

vortex-mask/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ impl Mask {
303303
Self::from_indices(len, intersection)
304304
}
305305

306+
/// Clears the mask of all data. Drops any allocated capacity.
307+
pub fn clear(&mut self) {
308+
*self = Self::new_false(0);
309+
}
310+
306311
/// Returns the length of the mask (not the number of true values).
307312
#[inline]
308313
pub fn len(&self) -> usize {

vortex-vector/src/binaryview/vector.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ impl<T: BinaryViewType> VectorOps for BinaryViewVector<T> {
211211
todo!()
212212
}
213213

214+
fn clear(&mut self) {
215+
self.views.clear();
216+
self.validity = Mask::new_true(0);
217+
self.buffers = Arc::new(Box::new([]));
218+
}
219+
214220
fn try_into_mut(self) -> Result<BinaryViewVectorMut<T>, Self> {
215221
let views_mut = match self.views.try_into_mut() {
216222
Ok(views_mut) => views_mut,

vortex-vector/src/bool/vector.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ impl VectorOps for BoolVector {
9999
Self { bits, validity }
100100
}
101101

102+
fn clear(&mut self) {
103+
self.bits.clear();
104+
self.validity.clear();
105+
}
106+
102107
fn try_into_mut(self) -> Result<BoolVectorMut, Self> {
103108
let bits = match self.bits.try_into_mut() {
104109
Ok(bits) => bits,

vortex-vector/src/decimal/generic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ impl<D: NativeDecimalType> VectorOps for DVector<D> {
188188
}
189189
}
190190

191+
fn clear(&mut self) {
192+
self.elements.clear();
193+
self.validity.clear();
194+
}
195+
191196
fn try_into_mut(self) -> Result<DVectorMut<D>, Self> {
192197
let elements = match self.elements.try_into_mut() {
193198
Ok(elements) => elements,

vortex-vector/src/decimal/vector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ impl VectorOps for DecimalVector {
7373
match_each_dvector!(self, |v| { DecimalVector::from(v.slice(range)) })
7474
}
7575

76+
fn clear(&mut self) {
77+
match_each_dvector!(self, |v| { v.clear() })
78+
}
79+
7680
fn try_into_mut(self) -> Result<DecimalVectorMut, Self> {
7781
match_each_dvector!(self, |v| {
7882
v.try_into_mut()

vortex-vector/src/fixed_size_list/vector.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ impl VectorOps for FixedSizeListVector {
165165
todo!()
166166
}
167167

168+
fn clear(&mut self) {
169+
Arc::make_mut(&mut self.elements).clear();
170+
self.validity.clear();
171+
self.len = 0;
172+
}
173+
168174
fn try_into_mut(self) -> Result<FixedSizeListVectorMut, Self> {
169175
let len = self.len;
170176
let list_size = self.list_size;

vortex-vector/src/listview/vector.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ impl VectorOps for ListViewVector {
220220
todo!()
221221
}
222222

223+
fn clear(&mut self) {
224+
self.offsets.clear();
225+
self.sizes.clear();
226+
Arc::make_mut(&mut self.elements).clear();
227+
self.validity.clear();
228+
self.len = 0;
229+
}
230+
223231
fn try_into_mut(self) -> Result<ListViewVectorMut, Self> {
224232
// Try to unwrap the `Arc`.
225233
let elements = match Arc::try_unwrap(self.elements) {

vortex-vector/src/null/vector.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ impl VectorOps for NullVector {
5757
Self::new(len)
5858
}
5959

60+
fn clear(&mut self) {
61+
self.len = 0;
62+
self.validity = Mask::AllFalse(0);
63+
}
64+
6065
fn try_into_mut(self) -> Result<NullVectorMut, Self> {
6166
Ok(NullVectorMut::new(self.len))
6267
}

vortex-vector/src/primitive/generic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ impl<T: NativePType> VectorOps for PVector<T> {
142142
Self::new(elements, validity)
143143
}
144144

145+
fn clear(&mut self) {
146+
self.elements.clear();
147+
self.validity.clear();
148+
}
149+
145150
/// Try to convert self into a mutable vector.
146151
fn try_into_mut(self) -> Result<PVectorMut<T>, Self> {
147152
let elements = match self.elements.try_into_mut() {

vortex-vector/src/primitive/vector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ impl VectorOps for PrimitiveVector {
8686
match_each_pvector!(self, |v| { v.slice(range).into() })
8787
}
8888

89+
fn clear(&mut self) {
90+
match_each_pvector!(self, |v| { v.clear() })
91+
}
92+
8993
fn try_into_mut(self) -> Result<PrimitiveVectorMut, Self> {
9094
match_each_pvector!(self, |v| {
9195
v.try_into_mut()

0 commit comments

Comments
 (0)