Skip to content

Commit bea1b59

Browse files
committed
remove decimal/generic_mut_impl.rs
Signed-off-by: Connor Tsui <[email protected]>
1 parent eb3558f commit bea1b59

File tree

3 files changed

+44
-51
lines changed

3 files changed

+44
-51
lines changed

vortex-vector/src/decimal/generic_mut.rs

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

44
use vortex_buffer::BufferMut;
55
use vortex_dtype::{NativeDecimalType, PrecisionScale};
6+
use vortex_error::{VortexResult, vortex_bail};
67
use vortex_mask::MaskMut;
78

89
use crate::{DVector, VectorMutOps, VectorOps};
@@ -15,6 +16,49 @@ pub struct DVectorMut<D> {
1516
pub(super) validity: MaskMut,
1617
}
1718

19+
impl<D: NativeDecimalType> DVectorMut<D> {
20+
/// Get the precision/scale of the decimal vector.
21+
pub fn precision_scale(&self) -> PrecisionScale<D> {
22+
self.ps
23+
}
24+
25+
/// Get a nullable element at the given index.
26+
pub fn get(&self, index: usize) -> Option<&D> {
27+
self.validity.value(index).then(|| &self.elements[index])
28+
}
29+
30+
/// Appends a new element to the end of the vector.
31+
///
32+
/// # Errors
33+
///
34+
/// Returns an error if the value is out of bounds for the vector's precision/scale.
35+
pub fn try_push(&mut self, value: D) -> VortexResult<()> {
36+
if !self.ps.is_valid(value) {
37+
vortex_bail!("Value {:?} is out of bounds for {}", value, self.ps,);
38+
}
39+
40+
self.elements.push(value);
41+
self.validity.append_n(true, 1);
42+
Ok(())
43+
}
44+
45+
/// Returns a mutable reference to the underlying elements buffer.
46+
///
47+
/// # Safety
48+
///
49+
/// Modifying the elements buffer directly may violate the precision/scale constraints.
50+
/// The caller must ensure that any modifications maintain these invariants.
51+
pub unsafe fn elements_mut(&mut self) -> &mut [D] {
52+
&mut self.elements
53+
}
54+
}
55+
56+
impl<D: NativeDecimalType> AsRef<[D]> for DVectorMut<D> {
57+
fn as_ref(&self) -> &[D] {
58+
&self.elements
59+
}
60+
}
61+
1862
impl<D: NativeDecimalType> VectorMutOps for DVectorMut<D> {
1963
type Immutable = DVector<D>;
2064

vortex-vector/src/decimal/generic_mut_impl.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

vortex-vector/src/decimal/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod generic;
55
pub use generic::DVector;
66

77
mod generic_mut;
8-
mod generic_mut_impl;
98
pub use generic_mut::DVectorMut;
109

1110
mod vector;

0 commit comments

Comments
 (0)