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

Commit

Permalink
Add extend_from_iter into growable trait
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Jan 18, 2022
1 parent b70483e commit e235988
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions benches/growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ fn add_benchmark(c: &mut Criterion) {
})
});

c.bench_function("growable::dyn_primitive::non_null::non_null", |b| {
b.iter(|| {
let mut a: Box<dyn Growable> =
Box::new(GrowablePrimitive::new(vec![&i32_array], false, 1026 * 10));

let iter = values.clone().into_iter().map(|start| (0, start, 10));
a.extend_from_iter(Box::new(iter));
})
});

let i32_array = create_primitive_array::<i32>(1026 * 10, 0.0);
c.bench_function("growable::primitive::non_null::null", |b| {
b.iter(|| {
Expand Down
7 changes: 7 additions & 0 deletions src/array/growable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ pub trait Growable<'a> {
/// Extends this [`Growable`] with null elements, disregarding the bound arrays
fn extend_validity(&mut self, additional: usize);

/// Extends this [`Growable`] by iterator.
fn extend_from_iter(&mut self, iter: Box<dyn Iterator<Item = (usize, usize, usize)>>) {
for (index, start, len) in iter {
self.extend(index, start, len);
}
}

/// Converts this [`Growable`] to an [`Arc<dyn Array>`], thereby finishing the mutation.
/// Self will be empty after such operation.
fn as_arc(&mut self) -> std::sync::Arc<dyn Array> {
Expand Down

0 comments on commit e235988

Please sign in to comment.