Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new_with_capacity() for all other geometry types #279

Merged
merged 7 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/array/multilinestring/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Arc;
// use super::array::check;
use crate::array::mutable_offset::OffsetsBuilder;
use crate::array::{
MultiLineStringArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutablePolygonArray,
WKBArray,
CoordType, MultiLineStringArray, MutableCoordBuffer, MutableInterleavedCoordBuffer,
MutablePolygonArray, MutableSeparatedCoordBuffer, WKBArray,
};
use crate::error::{GeoArrowError, Result};
use crate::geo_traits::{LineStringTrait, MultiLineStringTrait};
Expand Down Expand Up @@ -41,15 +41,40 @@ impl<O: OffsetSizeTrait> MutableMultiLineStringArray<O> {
MutablePolygonArray::new().into()
}

pub fn new_with_options(coord_type: CoordType) -> Self {
Self::with_capacities_and_options(0, 0, 0, coord_type)
}

/// Creates a new [`MutableMultiLineStringArray`] with a capacity.
pub fn with_capacities(
coord_capacity: usize,
ring_capacity: usize,
geom_capacity: usize,
) -> Self {
let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity);
Self::with_capacities_and_options(
coord_capacity,
ring_capacity,
geom_capacity,
Default::default(),
)
}

pub fn with_capacities_and_options(
coord_capacity: usize,
ring_capacity: usize,
geom_capacity: usize,
coord_type: CoordType,
) -> Self {
let coords = match coord_type {
CoordType::Interleaved => MutableCoordBuffer::Interleaved(
MutableInterleavedCoordBuffer::with_capacity(coord_capacity),
),
CoordType::Separated => MutableCoordBuffer::Separated(
MutableSeparatedCoordBuffer::with_capacity(coord_capacity),
),
};
Self {
coords: MutableCoordBuffer::Interleaved(coords),
coords,
geom_offsets: OffsetsBuilder::with_capacity(geom_capacity),
ring_offsets: OffsetsBuilder::with_capacity(ring_capacity),
validity: NullBufferBuilder::new(geom_capacity),
Expand Down
30 changes: 25 additions & 5 deletions src/array/multipoint/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Arc;
// use super::array::check;
use crate::array::mutable_offset::OffsetsBuilder;
use crate::array::{
MultiPointArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableLineStringArray,
WKBArray,
CoordType, MultiPointArray, MutableCoordBuffer, MutableInterleavedCoordBuffer,
MutableLineStringArray, MutableSeparatedCoordBuffer, WKBArray,
};
use crate::error::{GeoArrowError, Result};
use crate::geo_traits::{MultiPointTrait, PointTrait};
Expand All @@ -29,14 +29,34 @@ pub struct MutableMultiPointArray<O: OffsetSizeTrait> {
impl<O: OffsetSizeTrait> MutableMultiPointArray<O> {
/// Creates a new empty [`MutableMultiPointArray`].
pub fn new() -> Self {
Self::with_capacities(0, 0)
Self::new_with_options(Default::default())
}

/// Creates a new [`MutableMultiPointArray`] with a specified [`CoordType`]
pub fn new_with_options(coord_type: CoordType) -> Self {
Self::with_capacities_and_options(0, 0, coord_type)
}
/// Creates a new [`MutableMultiPointArray`] with a capacity.
pub fn with_capacities(coord_capacity: usize, geom_capacity: usize) -> Self {
let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity);
Self::with_capacities_and_options(coord_capacity, geom_capacity, Default::default())
}

// with capacities and options enables us to write with_capacities based on this method
pub fn with_capacities_and_options(
coord_capacity: usize,
geom_capacity: usize,
coord_type: CoordType,
) -> Self {
let coords = match coord_type {
CoordType::Interleaved => MutableCoordBuffer::Interleaved(
MutableInterleavedCoordBuffer::with_capacity(coord_capacity),
),
CoordType::Separated => MutableCoordBuffer::Separated(
MutableSeparatedCoordBuffer::with_capacity(coord_capacity),
),
};
Self {
coords: MutableCoordBuffer::Interleaved(coords),
coords,
geom_offsets: OffsetsBuilder::with_capacity(geom_capacity),
validity: NullBufferBuilder::new(geom_capacity),
}
Expand Down
37 changes: 33 additions & 4 deletions src/array/multipolygon/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::sync::Arc;
// use super::array::check;
use crate::array::mutable_offset::OffsetsBuilder;
use crate::array::{
MultiPolygonArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, WKBArray,
CoordType, MultiPolygonArray, MutableCoordBuffer, MutableInterleavedCoordBuffer,
MutableSeparatedCoordBuffer, WKBArray,
};
use crate::error::{GeoArrowError, Result};
use crate::geo_traits::{LineStringTrait, MultiPolygonTrait, PolygonTrait};
Expand Down Expand Up @@ -44,7 +45,11 @@ pub struct MutableMultiPolygonArray<O: OffsetSizeTrait> {
impl<O: OffsetSizeTrait> MutableMultiPolygonArray<O> {
/// Creates a new empty [`MutableMultiPolygonArray`].
pub fn new() -> Self {
Self::with_capacities(0, 0, 0, 0)
Self::new_with_options(Default::default())
}

pub fn new_with_options(coord_type: CoordType) -> Self {
Self::with_capacities_and_options(0, 0, 0, 0, coord_type)
}

/// Creates a new [`MutableMultiPolygonArray`] with a capacity.
Expand All @@ -54,9 +59,33 @@ impl<O: OffsetSizeTrait> MutableMultiPolygonArray<O> {
polygon_capacity: usize,
geom_capacity: usize,
) -> Self {
let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity);
Self::with_capacities_and_options(
coord_capacity,
ring_capacity,
polygon_capacity,
geom_capacity,
Default::default(),
)
}

pub fn with_capacities_and_options(
JosiahParry marked this conversation as resolved.
Show resolved Hide resolved
coord_capacity: usize,
ring_capacity: usize,
polygon_capacity: usize,
geom_capacity: usize,
coord_type: CoordType,
) -> Self {
let coords = match coord_type {
CoordType::Interleaved => MutableCoordBuffer::Interleaved(
MutableInterleavedCoordBuffer::with_capacity(coord_capacity),
),
CoordType::Separated => MutableCoordBuffer::Separated(
MutableSeparatedCoordBuffer::with_capacity(coord_capacity),
),
};

Self {
coords: MutableCoordBuffer::Interleaved(coords),
coords,
geom_offsets: OffsetsBuilder::with_capacity(geom_capacity),
polygon_offsets: OffsetsBuilder::with_capacity(polygon_capacity),
ring_offsets: OffsetsBuilder::with_capacity(ring_capacity),
Expand Down
33 changes: 29 additions & 4 deletions src/array/polygon/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Arc;
// use super::array::check;
use crate::array::mutable_offset::OffsetsBuilder;
use crate::array::{
MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableMultiLineStringArray, PolygonArray,
WKBArray,
CoordType, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableMultiLineStringArray,
MutableSeparatedCoordBuffer, PolygonArray, WKBArray,
};
use crate::error::{GeoArrowError, Result};
use crate::geo_traits::{LineStringTrait, PolygonTrait};
Expand Down Expand Up @@ -43,15 +43,40 @@ impl<O: OffsetSizeTrait> MutablePolygonArray<O> {
Self::with_capacities(0, 0, 0)
}

pub fn new_with_options(coord_type: CoordType) -> Self {
Self::with_capacities_and_options(0, 0, 0, coord_type)
}

/// Creates a new [`MutablePolygonArray`] with given capacities and no validity.
pub fn with_capacities(
coord_capacity: usize,
ring_capacity: usize,
geom_capacity: usize,
) -> Self {
let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity);
Self::with_capacities_and_options(
coord_capacity,
ring_capacity,
geom_capacity,
Default::default(),
)
}

pub fn with_capacities_and_options(
coord_capacity: usize,
ring_capacity: usize,
geom_capacity: usize,
coord_type: CoordType,
) -> Self {
let coords = match coord_type {
CoordType::Interleaved => MutableCoordBuffer::Interleaved(
MutableInterleavedCoordBuffer::with_capacity(coord_capacity),
),
CoordType::Separated => MutableCoordBuffer::Separated(
MutableSeparatedCoordBuffer::with_capacity(coord_capacity),
),
};
Self {
coords: MutableCoordBuffer::Interleaved(coords),
coords,
geom_offsets: OffsetsBuilder::with_capacity(geom_capacity),
ring_offsets: OffsetsBuilder::with_capacity(ring_capacity),
validity: NullBufferBuilder::new(geom_capacity),
Expand Down
Loading