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

Commit

Permalink
Add MutableArray::as_box
Browse files Browse the repository at this point in the history
This basically just changes the impls of `as_arc` to `as_box` and uses
the `From<Box<T>> for Arc<T>` impl to provide a default implementation
for `as_arc`.
  • Loading branch information
sd2k committed Sep 25, 2021
1 parent 885e6c1 commit 6c98aa1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/array/binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl<O: Offset> MutableArray for MutableBinaryArray<O> {
&self.validity
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(BinaryArray::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(BinaryArray::from_data(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
std::mem::take(&mut self.values).into(),
Expand Down
4 changes: 2 additions & 2 deletions src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ impl MutableArray for MutableBooleanArray {
&self.validity
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(BooleanArray::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(BooleanArray::from_data(
self.data_type.clone(),
std::mem::take(&mut self.values).into(),
std::mem::take(&mut self.validity).map(|x| x.into()),
Expand Down
4 changes: 2 additions & 2 deletions src/array/dictionary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl<K: DictionaryKey, M: 'static + MutableArray> MutableArray for MutableDictio
self.keys.validity()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(DictionaryArray::<K>::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(DictionaryArray::<K>::from_data(
std::mem::take(&mut self.keys).into(),
self.values.as_arc(),
))
Expand Down
6 changes: 2 additions & 4 deletions src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use crate::{
array::{Array, MutableArray},
bitmap::MutableBitmap,
Expand Down Expand Up @@ -173,8 +171,8 @@ impl MutableArray for MutableFixedSizeBinaryArray {
&self.validity
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(FixedSizeBinaryArray::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(FixedSizeBinaryArray::from_data(
DataType::FixedSizeBinary(self.size as i32),
std::mem::take(&mut self.values).into(),
std::mem::take(&mut self.validity).map(|x| x.into()),
Expand Down
6 changes: 2 additions & 4 deletions src/array/fixed_size_list/mutable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use crate::{
array::{
Array, MutableArray, MutableBinaryArray, MutablePrimitiveArray, MutableUtf8Array, Offset,
Expand Down Expand Up @@ -69,8 +67,8 @@ impl<M: MutableArray + 'static> MutableArray for MutableFixedSizeListArray<M> {
&self.validity
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(FixedSizeListArray::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(FixedSizeListArray::from_data(
self.data_type.clone(),
self.values.as_arc(),
std::mem::take(&mut self.validity).map(|x| x.into()),
Expand Down
4 changes: 2 additions & 2 deletions src/array/list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ impl<O: Offset, M: MutableArray + 'static> MutableArray for MutableListArray<O,
&self.validity
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(ListArray::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(ListArray::from_data(
self.data_type.clone(),
std::mem::take(&mut self.offsets).into(),
self.values.as_arc(),
Expand Down
9 changes: 7 additions & 2 deletions src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ pub trait MutableArray: std::fmt::Debug {
/// The optional validity of the array.
fn validity(&self) -> &Option<MutableBitmap>;

/// Convert itself to an (immutable) [`Array`].
fn as_arc(&mut self) -> Arc<dyn Array>;
/// Convert itself to an (immutable) ['Array'].
fn as_box(&mut self) -> Box<dyn Array>;

/// Convert itself to an (immutable) atomically reference counted [`Array`].
fn as_arc(&mut self) -> Arc<dyn Array> {
self.as_box().into()
}

/// Convert to `Any`, to enable dynamic casting.
fn as_any(&self) -> &dyn Any;
Expand Down
4 changes: 2 additions & 2 deletions src/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ impl<T: NativeType> MutableArray for MutablePrimitiveArray<T> {
&self.validity
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(PrimitiveArray::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(PrimitiveArray::from_data(
self.data_type.clone(),
std::mem::take(&mut self.values).into(),
std::mem::take(&mut self.validity).map(|x| x.into()),
Expand Down
4 changes: 2 additions & 2 deletions src/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ impl<O: Offset> MutableArray for MutableUtf8Array<O> {
&self.validity
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(Utf8Array::from_data(
fn as_box(&mut self) -> Box<dyn Array> {
Box::new(Utf8Array::from_data(
Self::default_data_type(),
std::mem::take(&mut self.offsets).into(),
std::mem::take(&mut self.values).into(),
Expand Down

0 comments on commit 6c98aa1

Please sign in to comment.