sparrow 0.3.0
Loading...
Searching...
No Matches
sparrow::array Class Reference

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.
 
arrayoperator= (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.
 
arrayoperator= (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
 

Detailed Description

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.

Examples
record_batch_example.cpp.

Definition at line 38 of file array_api.hpp.

Member Typedef Documentation

◆ const_reference

◆ size_type

using sparrow::array::size_type = std::size_t

Definition at line 42 of file array_api.hpp.

◆ value_type

◆ visit_result_t

template<class F>
using sparrow::array::visit_result_t = std::invoke_result_t<F, null_array>

Definition at line 197 of file array_api.hpp.

Constructor & Destructor Documentation

◆ array() [1/9]

sparrow::array::array ( )
default

Constructs an empty array.

Here is the caller graph for this function:

◆ array() [2/9]

template<layout A>
requires (not std::is_lvalue_reference_v<A>)
sparrow::array::array ( A && a)
explicit

Constructs an Array from the given typed layout.

The ownership of the layout is transferred to the Array.

Parameters
aAn rvalue reference to the typed layout.

Definition at line 24 of file array.hpp.

Here is the call graph for this function:

◆ array() [3/9]

template<layout A>
sparrow::array::array ( A * a)
explicit

Constructs an Array from the given typed layout.

The ownership of the layout is not transferred to the Array and the layout's lifetime must be longer than that of the Array.

Parameters
aA pointer to the typed layout.

Definition at line 30 of file array.hpp.

◆ array() [4/9]

template<layout A>
sparrow::array::array ( std::shared_ptr< A > a)
explicit

Constructs an Array from the given typed layout.

The ownership of the layout is shared by this Array and any other shared pointer referencing it.

Parameters
aA shared pointer holding the layout.

Definition at line 36 of file array.hpp.

◆ array() [5/9]

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.

Parameters
arrayThe ArrowArray structure to transfer into the Array.
schemaThe ArowSchema structure to transfer into the Array.
Here is the call graph for this function:

◆ array() [6/9]

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.

Parameters
arrayThe ArrowArray structure to transfer into the Array.
schemaThe ArrowSchema to reference in the Array.
Here is the call graph for this function:

◆ array() [7/9]

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.

Parameters
arrayThe ArrowArray structure to reference in the Array.
schemaThe ArrowSchema to reference in the Array.
Here is the call graph for this function:

◆ array() [8/9]

sparrow::array::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.

Parameters
rhsThe array to copy.
Here is the call graph for this function:

◆ array() [9/9]

sparrow::array::array ( array && rhs)
default

The move constructor.

Parameters
rhsThe array to move.
Here is the call graph for this function:

Member Function Documentation

◆ at()

SPARROW_API const_reference sparrow::array::at ( size_type index) const
Returns
a constant reference to the element at specified index, with bounds checking.
Parameters
indexThe position of the element in the array.
Exceptions
std::out_of_rangeif index is not within the range of the container.

◆ back()

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.

◆ data_type()

SPARROW_API enum data_type sparrow::array::data_type ( ) const
Returns
the data type of the Array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

SPARROW_API bool sparrow::array::empty ( ) const

Checks if the array has no element, i.e.

whether size() == 0.

◆ front()

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.

◆ name()

SPARROW_API std::optional< std::string_view > sparrow::array::name ( ) const
Returns
the name of the Array or an empty string if the array does not have a name.
Here is the caller graph for this function:

◆ operator=() [1/2]

array & sparrow::array::operator= ( array && rhs)
default

The move assignment operator.

Parameters
rhsThe array to move.
Here is the call graph for this function:

◆ operator=() [2/2]

array & sparrow::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.

Parameters
rhsThe array to assign.
Here is the call graph for this function:

◆ operator[]()

SPARROW_API const_reference sparrow::array::operator[] ( size_type index) const
Returns
a constant reference to the element at specified index.
Parameters
indexThe position of the element in the Array. Must be less than size.

◆ set_name()

SPARROW_API void sparrow::array::set_name ( std::optional< std::string_view > name)

Sets the name of the array to name.

Parameters
nameThe new name of the array.
Here is the call graph for this function:

◆ size()

SPARROW_API size_type sparrow::array::size ( ) const
Returns
the number of elements in the array.

◆ slice()

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.

Parameters
startThe index of the first element to keep. Must be less than end.
endThe index of the first element to discard. Must be less than the size of the buffers.
Here is the call graph for this function:

◆ slice_view()

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.

Parameters
startThe index of the first element to keep. Must be less than end.
endThe index of the first element to discard. Must be less than the size of the buffers.
Here is the call graph for this function:

◆ visit()

template<class F>
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.

Parameters
funcThe functor to apply.
Returns
The result of calling the functor on the internal layout.

Definition at line 42 of file array.hpp.

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ detail::array_access

friend class detail::array_access
friend

Definition at line 242 of file array_api.hpp.


The documentation for this class was generated from the following files: