From 595a310cf783946f2bb6beef17dbb6d7bef77f8b Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 27 Nov 2023 09:12:05 -0500 Subject: [PATCH 1/7] add multable multilinepoint array with options --- src/array/multipoint/mutable.rs | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/array/multipoint/mutable.rs b/src/array/multipoint/mutable.rs index e48017c5..93b4bf94 100644 --- a/src/array/multipoint/mutable.rs +++ b/src/array/multipoint/mutable.rs @@ -3,7 +3,11 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MultiPointArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableLineStringArray, + CoordType, + MultiPointArray, + MutableCoordBuffer, + MutableInterleavedCoordBuffer, MutableSeparatedCoordBuffer, + MutableLineStringArray, WKBArray, }; use crate::error::{GeoArrowError, Result}; @@ -29,14 +33,38 @@ pub struct MutableMultiPointArray { impl MutableMultiPointArray { /// 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), } From 10d691206618f02d822d26e4e7d9ac2786b48543 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 27 Nov 2023 09:20:34 -0500 Subject: [PATCH 2/7] new_with_options() for MultiLineString --- src/array/multilinestring/mutable.rs | 41 +++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/array/multilinestring/mutable.rs b/src/array/multilinestring/mutable.rs index 899cd2c4..2a620394 100644 --- a/src/array/multilinestring/mutable.rs +++ b/src/array/multilinestring/mutable.rs @@ -3,7 +3,9 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MultiLineStringArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutablePolygonArray, + CoordType, MutableCoordBuffer, + MutableInterleavedCoordBuffer, MutableSeparatedCoordBuffer, + MultiLineStringArray, MutablePolygonArray, WKBArray, }; use crate::error::{GeoArrowError, Result}; @@ -41,18 +43,43 @@ impl MutableMultiLineStringArray { 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 { - coords: MutableCoordBuffer::Interleaved(coords), - geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), - ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), - validity: NullBufferBuilder::new(geom_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, + geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), + ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), + validity: NullBufferBuilder::new(geom_capacity) } } From d237a305a7b1f192e25468cb4ecec90f79797cdf Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 27 Nov 2023 09:26:54 -0500 Subject: [PATCH 3/7] new_with_options() for Polygon --- src/array/polygon/mutable.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/array/polygon/mutable.rs b/src/array/polygon/mutable.rs index 4cee3f0c..15b05f7d 100644 --- a/src/array/polygon/mutable.rs +++ b/src/array/polygon/mutable.rs @@ -3,9 +3,11 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableMultiLineStringArray, PolygonArray, + CoordType, MutableCoordBuffer, + MutableInterleavedCoordBuffer, MutableSeparatedCoordBuffer, + MutableMultiLineStringArray, PolygonArray, WKBArray, -}; +}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, PolygonTrait}; use crate::io::wkb::reader::polygon::WKBPolygon; @@ -43,15 +45,35 @@ impl MutablePolygonArray { 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), From 108701241b6953e59f76889504ac3b49b9350165 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 27 Nov 2023 09:30:23 -0500 Subject: [PATCH 4/7] new_with_options() for MultiPolygon --- src/array/multipolygon/mutable.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/array/multipolygon/mutable.rs b/src/array/multipolygon/mutable.rs index d3cf69b7..414ed22d 100644 --- a/src/array/multipolygon/mutable.rs +++ b/src/array/multipolygon/mutable.rs @@ -3,7 +3,9 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MultiPolygonArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, WKBArray, + CoordType, MutableSeparatedCoordBuffer, + MutableCoordBuffer, MutableInterleavedCoordBuffer, + MultiPolygonArray, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, MultiPolygonTrait, PolygonTrait}; @@ -64,6 +66,31 @@ impl MutableMultiPolygonArray { } } + pub fn with_capacities_and_options( + 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, + geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), + polygon_offsets: OffsetsBuilder::with_capacity(polygon_capacity), + ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), + validity: NullBufferBuilder::new(geom_capacity) + } + } + /// Reserves capacity for at least `additional` more LineStrings to be inserted /// in the given `Vec`. The collection may reserve more space to /// speculatively avoid frequent reallocations. After calling `reserve`, From a7fdc83d7a7feaf1916c2c426bd5629cb13e5092 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 27 Nov 2023 09:35:26 -0500 Subject: [PATCH 5/7] run cargo fmt --- src/array/multilinestring/mutable.rs | 26 ++++++++++++-------------- src/array/multipoint/mutable.rs | 14 +++----------- src/array/multipolygon/mutable.rs | 19 +++++++++---------- src/array/polygon/mutable.rs | 15 +++++++++------ 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/array/multilinestring/mutable.rs b/src/array/multilinestring/mutable.rs index 2a620394..c23823b7 100644 --- a/src/array/multilinestring/mutable.rs +++ b/src/array/multilinestring/mutable.rs @@ -3,10 +3,8 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - CoordType, MutableCoordBuffer, - MutableInterleavedCoordBuffer, MutableSeparatedCoordBuffer, - MultiLineStringArray, MutablePolygonArray, - WKBArray, + CoordType, MultiLineStringArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, + MutablePolygonArray, MutableSeparatedCoordBuffer, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, MultiLineStringTrait}; @@ -46,7 +44,7 @@ impl MutableMultiLineStringArray { 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, @@ -54,10 +52,10 @@ impl MutableMultiLineStringArray { geom_capacity: usize, ) -> Self { Self::with_capacities_and_options( - coord_capacity, - ring_capacity, - geom_capacity, - Default::default() + coord_capacity, + ring_capacity, + geom_capacity, + Default::default(), ) } @@ -75,11 +73,11 @@ impl MutableMultiLineStringArray { MutableSeparatedCoordBuffer::with_capacity(coord_capacity), ), }; - Self { - coords, - geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), - ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), - validity: NullBufferBuilder::new(geom_capacity) + Self { + coords, + geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), + ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), + validity: NullBufferBuilder::new(geom_capacity), } } diff --git a/src/array/multipoint/mutable.rs b/src/array/multipoint/mutable.rs index 93b4bf94..26ed09fd 100644 --- a/src/array/multipoint/mutable.rs +++ b/src/array/multipoint/mutable.rs @@ -3,12 +3,8 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - CoordType, - MultiPointArray, - MutableCoordBuffer, - MutableInterleavedCoordBuffer, MutableSeparatedCoordBuffer, - MutableLineStringArray, - WKBArray, + CoordType, MultiPointArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, + MutableLineStringArray, MutableSeparatedCoordBuffer, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{MultiPointTrait, PointTrait}; @@ -42,11 +38,7 @@ impl MutableMultiPointArray { } /// Creates a new [`MutableMultiPointArray`] with a capacity. pub fn with_capacities(coord_capacity: usize, geom_capacity: usize) -> Self { - Self::with_capacities_and_options( - coord_capacity, - geom_capacity, - Default::default() - ) + 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 diff --git a/src/array/multipolygon/mutable.rs b/src/array/multipolygon/mutable.rs index 414ed22d..aad02105 100644 --- a/src/array/multipolygon/mutable.rs +++ b/src/array/multipolygon/mutable.rs @@ -3,9 +3,8 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - CoordType, MutableSeparatedCoordBuffer, - MutableCoordBuffer, MutableInterleavedCoordBuffer, - MultiPolygonArray, WKBArray, + CoordType, MultiPolygonArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, + MutableSeparatedCoordBuffer, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, MultiPolygonTrait, PolygonTrait}; @@ -71,7 +70,7 @@ impl MutableMultiPolygonArray { ring_capacity: usize, polygon_capacity: usize, geom_capacity: usize, - coord_type: CoordType + coord_type: CoordType, ) -> Self { let coords = match coord_type { CoordType::Interleaved => MutableCoordBuffer::Interleaved( @@ -82,12 +81,12 @@ impl MutableMultiPolygonArray { ), }; - Self { - coords, - geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), - polygon_offsets: OffsetsBuilder::with_capacity(polygon_capacity), - ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), - validity: NullBufferBuilder::new(geom_capacity) + Self { + coords, + geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), + polygon_offsets: OffsetsBuilder::with_capacity(polygon_capacity), + ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), + validity: NullBufferBuilder::new(geom_capacity), } } diff --git a/src/array/polygon/mutable.rs b/src/array/polygon/mutable.rs index 15b05f7d..d8af0c59 100644 --- a/src/array/polygon/mutable.rs +++ b/src/array/polygon/mutable.rs @@ -3,11 +3,9 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - CoordType, MutableCoordBuffer, - MutableInterleavedCoordBuffer, MutableSeparatedCoordBuffer, - MutableMultiLineStringArray, PolygonArray, - WKBArray, -}; + CoordType, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableMultiLineStringArray, + MutableSeparatedCoordBuffer, PolygonArray, WKBArray, +}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, PolygonTrait}; use crate::io::wkb::reader::polygon::WKBPolygon; @@ -55,7 +53,12 @@ impl MutablePolygonArray { ring_capacity: usize, geom_capacity: usize, ) -> Self { - Self::with_capacities_and_options(coord_capacity, ring_capacity, geom_capacity, Default::default()) + Self::with_capacities_and_options( + coord_capacity, + ring_capacity, + geom_capacity, + Default::default(), + ) } pub fn with_capacities_and_options( From c6ccc9ba79038c787017d666bb9bf99673b08bd3 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 27 Nov 2023 11:05:37 -0500 Subject: [PATCH 6/7] address PR comments --- src/array/multipolygon/mutable.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/array/multipolygon/mutable.rs b/src/array/multipolygon/mutable.rs index aad02105..60288e4b 100644 --- a/src/array/multipolygon/mutable.rs +++ b/src/array/multipolygon/mutable.rs @@ -45,7 +45,11 @@ pub struct MutableMultiPolygonArray { impl MutableMultiPolygonArray { /// 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. @@ -55,14 +59,13 @@ impl MutableMultiPolygonArray { polygon_capacity: usize, geom_capacity: usize, ) -> Self { - let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity); - Self { - coords: MutableCoordBuffer::Interleaved(coords), - geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), - polygon_offsets: OffsetsBuilder::with_capacity(polygon_capacity), - ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), - validity: NullBufferBuilder::new(geom_capacity), - } + Self::with_capacities_and_options( + coord_capacity, + ring_capacity, + polygon_capacity, + geom_capacity, + Default::default() + ) } pub fn with_capacities_and_options( From 2a5f6bb86d6f014c37eec1dcdb912201025ba9fc Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 27 Nov 2023 11:06:22 -0500 Subject: [PATCH 7/7] cargo fmt --- src/array/multipolygon/mutable.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/array/multipolygon/mutable.rs b/src/array/multipolygon/mutable.rs index 60288e4b..bdf3da02 100644 --- a/src/array/multipolygon/mutable.rs +++ b/src/array/multipolygon/mutable.rs @@ -45,7 +45,7 @@ pub struct MutableMultiPolygonArray { impl MutableMultiPolygonArray { /// Creates a new empty [`MutableMultiPolygonArray`]. pub fn new() -> Self { - Self::new_with_options(Default::default()) + Self::new_with_options(Default::default()) } pub fn new_with_options(coord_type: CoordType) -> Self { @@ -60,11 +60,11 @@ impl MutableMultiPolygonArray { geom_capacity: usize, ) -> Self { Self::with_capacities_and_options( - coord_capacity, - ring_capacity, - polygon_capacity, - geom_capacity, - Default::default() + coord_capacity, + ring_capacity, + polygon_capacity, + geom_capacity, + Default::default(), ) }