Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
get mutable offsets and values for Utf8 and binary arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
«ratal» committed Jan 16, 2024
1 parent 1c43a16 commit b929bcc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ impl<O: Offset> BinaryArray<O> {
impl_mut_validity!();
impl_into_array!();

/// Returns an option of a mutable reference to the values of this [`BinaryArray`].
pub fn get_mut_values(&mut self) -> Option<&mut [u8]> {
self.values.get_mut_slice()
}

/// Returns an option of a mutable reference to the values of this [`BinaryArray`].
pub fn get_mut_offsets(&mut self) -> Option<&mut [O]> {
self.offsets.get_mut_slice()
}

/// Returns its internal representation
#[must_use]
pub fn into_inner(self) -> (DataType, OffsetsBuffer<O>, Buffer<u8>, Option<Bitmap>) {
Expand Down
10 changes: 10 additions & 0 deletions src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ impl<O: Offset> Utf8Array<O> {
impl_mut_validity!();
impl_into_array!();

/// Returns an option of a mutable reference to the values of this [`Utf8Array`].
pub fn get_mut_values(&mut self) -> Option<&mut [u8]> {
self.values.get_mut_slice()
}

/// Returns an option of a mutable reference to the values of this [`Utf8Array`].
pub fn get_mut_offsets(&mut self) -> Option<&mut [O]> {
self.offsets.get_mut_slice()
}

/// Returns its internal representation
#[must_use]
pub fn into_inner(self) -> (DataType, OffsetsBuffer<O>, Buffer<u8>, Option<Bitmap>) {
Expand Down
10 changes: 10 additions & 0 deletions src/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ impl<O: Offset> OffsetsBuffer<O> {
.map_left(Self)
}

/// Returns a mutable reference to its slice, if possible.
///
/// This operation returns [`Some`] iff this [`OffsetsBuffer`]:
/// * has not been cloned (i.e. [`Arc`]`::get_mut` yields [`Some`])
/// * has not been imported from the c data interface (FFI)
#[inline]
pub fn get_mut_slice(&mut self) -> Option<&mut [O]> {
self.0.get_mut_slice()
}

/// Returns a reference to its internal [`Buffer`].
#[inline]
pub fn buffer(&self) -> &Buffer<O> {
Expand Down

0 comments on commit b929bcc

Please sign in to comment.