sparrow 0.3.0
|
Dynamically typed array encapsulating an Arrow layout. More...
#include <array_api.hpp>
Public Types | |
using | size_type = std::size_t |
using | value_type = array_traits::value_type |
using | const_reference = array_traits::const_reference |
template<class F> | |
using | visit_result_t = std::invoke_result_t<F, null_array> |
Public Member Functions | |
array ()=default | |
Constructs an empty array. | |
template<layout A> requires (not std::is_lvalue_reference_v<A>) | |
array (A &&a) | |
Constructs an Array from the given typed layout. | |
template<layout A> | |
array (A *a) | |
Constructs an Array from the given typed layout. | |
template<layout A> | |
array (std::shared_ptr< A > a) | |
Constructs an Array from the given typed layout. | |
SPARROW_API | array (ArrowArray &&array, ArrowSchema &&schema) |
Constructs an Array from the given Arrow C structures, whose ownerhips is transferred to the Array. | |
SPARROW_API | array (ArrowArray &&array, ArrowSchema *schema) |
Constructs an Array from the given Arrow C structures. | |
SPARROW_API | array (ArrowArray *array, ArrowSchema *schema) |
Constructs an array from the given Arrow C structures. | |
array (const array &rhs)=default | |
Performs a deep copy of the given array, even if it does not have the ownership of its internal data. | |
array & | operator= (const array &rhs)=default |
Overwrites the content of the array with a deep copy of the given array, event if it does not have the ownership of its internal data. | |
array (array &&rhs)=default | |
The move constructor. | |
array & | operator= (array &&rhs)=default |
The move assignment operator. | |
SPARROW_API enum data_type | data_type () const |
SPARROW_API std::optional< std::string_view > | name () const |
SPARROW_API void | set_name (std::optional< std::string_view > name) |
Sets the name of the array to name. | |
SPARROW_API bool | empty () const |
Checks if the array has no element, i.e. | |
SPARROW_API size_type | size () const |
SPARROW_API const_reference | at (size_type index) const |
SPARROW_API const_reference | operator[] (size_type index) const |
SPARROW_API const_reference | front () const |
Returns a constant reference to the first element in the container. | |
SPARROW_API const_reference | back () const |
Returns a constant reference to the last element in the container. | |
template<class F> | |
visit_result_t< F > | visit (F &&func) const |
Returns the result of calling the given functor func on the layout internally hold by the array. | |
SPARROW_API array | slice (size_type start, size_type end) const |
Slices the array to keep only the elements between the given start and end . | |
SPARROW_API array | slice_view (size_type start, size_type end) const |
Slices the array to keep only the elements between the given start and end . | |
Friends | |
class | detail::array_access |
Dynamically typed array encapsulating an Arrow layout.
The array
class is a dynamically typed container that encapsulates a typed Arrow layout. It provides accessors returning a variant of the suported data types, and supports the visitor pattern.
This class is designed to easily manipulate data from Arrow C structures and to easily extract Arrow C structures from layouts allocated with sparrow. It supports different models of ownership.
Definition at line 38 of file array_api.hpp.
Definition at line 44 of file array_api.hpp.
using sparrow::array::size_type = std::size_t |
Definition at line 42 of file array_api.hpp.
Definition at line 43 of file array_api.hpp.
using sparrow::array::visit_result_t = std::invoke_result_t<F, null_array> |
Definition at line 197 of file array_api.hpp.
|
default |
Constructs an empty array.
|
explicit |
|
explicit |
|
explicit |
SPARROW_API sparrow::array::array | ( | ArrowArray && | array, |
ArrowSchema && | schema ) |
Constructs an Array from the given Arrow C structures, whose ownerhips is transferred to the Array.
The user should not use array
nor schema
after calling this constructor.
array | The ArrowArray structure to transfer into the Array. |
schema | The ArowSchema structure to transfer into the Array. |
SPARROW_API sparrow::array::array | ( | ArrowArray && | array, |
ArrowSchema * | schema ) |
Constructs an Array from the given Arrow C structures.
The Array takes the ownerhship of the ArrowArray only. The used should not use array
after calling this constructor. schema
can still be used normally.
array | The ArrowArray structure to transfer into the Array. |
schema | The ArrowSchema to reference in the Array. |
SPARROW_API sparrow::array::array | ( | ArrowArray * | array, |
ArrowSchema * | schema ) |
Constructs an array from the given Arrow C structures.
Both structures are referenced from the Array and can still be used normally after calling this constructor.
array | The ArrowArray structure to reference in the Array. |
schema | The ArrowSchema to reference in the Array. |
|
default |
Performs a deep copy of the given array, even if it does not have the ownership of its internal data.
rhs | The array to copy. |
|
default |
The move constructor.
rhs | The array to move. |
SPARROW_API const_reference sparrow::array::at | ( | size_type | index | ) | const |
index
, with bounds checking.index | The position of the element in the array. |
std::out_of_range | if index is not within the range of the container. |
SPARROW_API const_reference sparrow::array::back | ( | ) | const |
Returns a constant reference to the last element in the container.
Calling back
on an empty array causes undefined behavior.
SPARROW_API enum data_type sparrow::array::data_type | ( | ) | const |
SPARROW_API bool sparrow::array::empty | ( | ) | const |
Checks if the array has no element, i.e.
whether size() == 0.
SPARROW_API const_reference sparrow::array::front | ( | ) | const |
Returns a constant reference to the first element in the container.
Calling front
on an empty array causes undefined behavior.
SPARROW_API std::optional< std::string_view > sparrow::array::name | ( | ) | const |
The move assignment operator.
rhs | The array to move. |
Overwrites the content of the array with a deep copy of the given array, event if it does not have the ownership of its internal data.
rhs | The array to assign. |
SPARROW_API const_reference sparrow::array::operator[] | ( | size_type | index | ) | const |
SPARROW_API void sparrow::array::set_name | ( | std::optional< std::string_view > | name | ) |
Sets the name of the array to name.
name | The new name of the array. |
SPARROW_API size_type sparrow::array::size | ( | ) | const |
SPARROW_API array sparrow::array::slice | ( | size_type | start, |
size_type | end ) const |
Slices the array to keep only the elements between the given start
and end
.
A copy of the Array is modified. The data is not modified, only the ArrowArray.offset and ArrowArray.length are updated. If end
is greater than the size of the buffers, the following elements will be invalid.
start | The index of the first element to keep. Must be less than end . |
end | The index of the first element to discard. Must be less than the size of the buffers. |
SPARROW_API array sparrow::array::slice_view | ( | size_type | start, |
size_type | end ) const |
Slices the array to keep only the elements between the given start
and end
.
A view of the Array is returned. The data is not modified, only the ArrowArray.offset and ArrowArray.length are updated. If end
is greater than the size of the buffers, the following elements will be invalid.
start | The index of the first element to keep. Must be less than end . |
end | The index of the first element to discard. Must be less than the size of the buffers. |
array::visit_result_t< F > sparrow::array::visit | ( | F && | func | ) | const |
Returns the result of calling the given functor func
on the layout internally hold by the array.
The actual type of the layout is retrieved via a visitor dispatch. func
must accept any kind of layout.
func | The functor to apply. |
Definition at line 42 of file array.hpp.
|
friend |
Definition at line 242 of file array_api.hpp.