11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4- //! Definition and implementation of [`PVectorMut <T>`].
4+ //! Definition and implementation of [`PVecMut <T>`].
55
66use vortex_buffer:: BufferMut ;
77use vortex_dtype:: NativePType ;
88use vortex_error:: { VortexExpect , VortexResult , vortex_ensure} ;
99use vortex_mask:: MaskMut ;
1010
11- use crate :: { PVector , VectorMutOps , VectorOps } ;
11+ use crate :: { PVec , VectorMutOps , VectorOps } ;
1212
1313/// A mutable vector of generic primitive values.
1414///
1515/// `T` is expected to be bound by [`NativePType`], which templates an internal [`BufferMut<T>`]
1616/// that stores the elements of the vector.
1717///
18- /// `PVectorMut <T>` is the primary way to construct primitive vectors. It provides efficient methods
19- /// for building vectors incrementally before converting them to an immutable [`PVector <T>`] using
18+ /// `PVecMut <T>` is the primary way to construct primitive vectors. It provides efficient methods
19+ /// for building vectors incrementally before converting them to an immutable [`PVec <T>`] using
2020/// the [`freeze`](crate::VectorMutOps::freeze) method.
2121///
2222/// # Examples
2323///
2424/// ## Creating and building a vector
2525///
2626/// ```
27- /// use vortex_vector::{PVectorMut , VectorMutOps};
27+ /// use vortex_vector::{PVecMut , VectorMutOps};
2828///
2929/// // Create with initial capacity for i32 values.
30- /// let mut vec = PVectorMut ::<i32>::with_capacity(10);
30+ /// let mut vec = PVecMut ::<i32>::with_capacity(10);
3131/// assert_eq!(vec.len(), 0);
3232/// assert!(vec.capacity() >= 10);
3333///
3434/// // Create from an iterator of optional values.
35- /// let mut vec = PVectorMut ::<i32>::from_iter([Some(1), None, Some(3)]);
35+ /// let mut vec = PVecMut ::<i32>::from_iter([Some(1), None, Some(3)]);
3636/// assert_eq!(vec.len(), 3);
3737///
3838/// // Works with different primitive types.
39- /// let mut f64_vec = PVectorMut ::<f64>::from_iter([1.5, 2.5, 3.5].map(Some));
39+ /// let mut f64_vec = PVecMut ::<f64>::from_iter([1.5, 2.5, 3.5].map(Some));
4040/// assert_eq!(f64_vec.len(), 3);
4141/// ```
4242///
4343/// ## Extending and appending
4444///
4545/// ```
46- /// use vortex_vector::{PVectorMut , VectorMutOps};
46+ /// use vortex_vector::{PVecMut , VectorMutOps};
4747///
48- /// let mut vec1 = PVectorMut ::<i32>::from_iter([1, 2].map(Some));
49- /// let vec2 = PVectorMut ::<i32>::from_iter([3, 4].map(Some)).freeze();
48+ /// let mut vec1 = PVecMut ::<i32>::from_iter([1, 2].map(Some));
49+ /// let vec2 = PVecMut ::<i32>::from_iter([3, 4].map(Some)).freeze();
5050///
5151/// // Extend from another vector.
5252/// vec1.extend_from_vector(&vec2);
@@ -60,9 +60,9 @@ use crate::{PVector, VectorMutOps, VectorOps};
6060/// ## Splitting and unsplitting
6161///
6262/// ```
63- /// use vortex_vector::{PVectorMut , VectorMutOps};
63+ /// use vortex_vector::{PVecMut , VectorMutOps};
6464///
65- /// let mut vec = PVectorMut ::<i64>::from_iter([10, 20, 30, 40, 50].map(Some));
65+ /// let mut vec = PVecMut ::<i64>::from_iter([10, 20, 30, 40, 50].map(Some));
6666///
6767/// // Split the vector at index 3.
6868/// let mut second_half = vec.split_off(3);
@@ -77,10 +77,10 @@ use crate::{PVector, VectorMutOps, VectorOps};
7777/// ## Working with nulls
7878///
7979/// ```
80- /// use vortex_vector::{PVectorMut , VectorMutOps};
80+ /// use vortex_vector::{PVecMut , VectorMutOps};
8181///
8282/// // Create a vector with some null values.
83- /// let mut vec = PVectorMut ::<u32>::from_iter([Some(100), None, Some(200), None]);
83+ /// let mut vec = PVecMut ::<u32>::from_iter([Some(100), None, Some(200), None]);
8484/// assert_eq!(vec.len(), 4);
8585///
8686/// // Add more nulls.
@@ -91,34 +91,34 @@ use crate::{PVector, VectorMutOps, VectorOps};
9191/// ## Converting to immutable
9292///
9393/// ```
94- /// use vortex_vector::{PVectorMut , VectorMutOps, VectorOps};
94+ /// use vortex_vector::{PVecMut , VectorMutOps, VectorOps};
9595///
96- /// let mut vec = PVectorMut ::<f32>::from_iter([1.0, 2.0, 3.0].map(Some));
96+ /// let mut vec = PVecMut ::<f32>::from_iter([1.0, 2.0, 3.0].map(Some));
9797///
9898/// // Freeze into an immutable vector.
9999/// let immutable = vec.freeze();
100100/// assert_eq!(immutable.len(), 3);
101101/// ```
102102#[ derive( Debug , Clone ) ]
103- pub struct PVectorMut < T > {
103+ pub struct PVecMut < T : NativePType > {
104104 /// The mutable buffer representing the vector elements.
105105 pub ( super ) elements : BufferMut < T > ,
106106 /// The validity mask (where `true` represents an element is **not** null).
107107 pub ( super ) validity : MaskMut ,
108108}
109109
110- impl < T > PVectorMut < T > {
111- /// Creates a new [`PVectorMut <T>`] from the given elements buffer and validity mask.
110+ impl < T : NativePType > PVecMut < T > {
111+ /// Creates a new [`PVecMut <T>`] from the given elements buffer and validity mask.
112112 ///
113113 /// # Panics
114114 ///
115115 /// Panics if the length of the validity mask does not match the length of the elements buffer.
116116 pub fn new ( elements : BufferMut < T > , validity : MaskMut ) -> Self {
117117 Self :: try_new ( elements, validity)
118- . vortex_expect ( "`PVectorMut ` validity mask must have the same length as elements" )
118+ . vortex_expect ( "`PVecMut ` validity mask must have the same length as elements" )
119119 }
120120
121- /// Tries to create a new [`PVectorMut <T>`] from the given elements buffer and validity mask.
121+ /// Tries to create a new [`PVecMut <T>`] from the given elements buffer and validity mask.
122122 ///
123123 /// # Errors
124124 ///
@@ -127,13 +127,13 @@ impl<T> PVectorMut<T> {
127127 pub fn try_new ( elements : BufferMut < T > , validity : MaskMut ) -> VortexResult < Self > {
128128 vortex_ensure ! (
129129 validity. len( ) == elements. len( ) ,
130- "`PVectorMut ` validity mask must have the same length as elements"
130+ "`PVecMut ` validity mask must have the same length as elements"
131131 ) ;
132132
133133 Ok ( Self { elements, validity } )
134134 }
135135
136- /// Creates a new [`PVectorMut <T>`] from the given elements buffer and validity mask without
136+ /// Creates a new [`PVecMut <T>`] from the given elements buffer and validity mask without
137137 /// validation.
138138 ///
139139 /// # Safety
@@ -146,7 +146,7 @@ impl<T> PVectorMut<T> {
146146 debug_assert_eq ! (
147147 elements. len( ) ,
148148 validity. len( ) ,
149- "`PVectorMut ` validity mask must have the same length as elements"
149+ "`PVecMut ` validity mask must have the same length as elements"
150150 ) ;
151151
152152 Self { elements, validity }
@@ -161,8 +161,8 @@ impl<T> PVectorMut<T> {
161161 }
162162}
163163
164- impl < T : NativePType > VectorMutOps for PVectorMut < T > {
165- type Immutable = PVector < T > ;
164+ impl < T : NativePType > VectorMutOps for PVecMut < T > {
165+ type Immutable = PVec < T > ;
166166
167167 fn len ( & self ) -> usize {
168168 self . elements . len ( )
@@ -178,7 +178,7 @@ impl<T: NativePType> VectorMutOps for PVectorMut<T> {
178178 }
179179
180180 /// Extends the vector by appending elements from another vector.
181- fn extend_from_vector ( & mut self , other : & PVector < T > ) {
181+ fn extend_from_vector ( & mut self , other : & PVec < T > ) {
182182 self . elements . extend_from_slice ( other. elements . as_slice ( ) ) ;
183183 self . validity . append_mask ( other. validity ( ) ) ;
184184 }
@@ -189,15 +189,15 @@ impl<T: NativePType> VectorMutOps for PVectorMut<T> {
189189 }
190190
191191 /// Freeze the vector into an immutable one.
192- fn freeze ( self ) -> PVector < T > {
193- PVector {
192+ fn freeze ( self ) -> PVec < T > {
193+ PVec {
194194 elements : self . elements . freeze ( ) ,
195195 validity : self . validity . freeze ( ) ,
196196 }
197197 }
198198
199199 fn split_off ( & mut self , at : usize ) -> Self {
200- PVectorMut {
200+ PVecMut {
201201 elements : self . elements . split_off ( at) ,
202202 validity : self . validity . split_off ( at) ,
203203 }
0 commit comments