Loading...
Searching...
No Matches
GrowableBuffer< PRIMITIVE > Class Template Reference

Discontiguous, one-dimensional buffer (which consists of multiple contiguous, one-dimensional panels) that can grow indefinitely by calling append. More...

#include <GrowableBuffer.h>

Public Member Functions

 GrowableBuffer (const BuilderOptions &options, std::unique_ptr< PRIMITIVE[]> ptr, int64_t length, int64_t reserved)
 Creates a GrowableBuffer from a full set of parameters.
 
 GrowableBuffer (const BuilderOptions &options)
 Creates a GrowableBuffer by allocating a new buffer, taking an options #reserved from options.
 
 GrowableBuffer (GrowableBuffer &&other) noexcept
 Move constructor.
 
size_t length () const
 Currently used number of elements.
 
const BuilderOptionsoptions () const
 Return options of this GrowableBuffer.
 
void clear ()
 Discards accumulated data, the #reserved returns to options.initial(), and a new #ptr is allocated.
 
PRIMITIVE last () const
 Last element in last panel.
 
size_t nbytes () const
 Currently used number of bytes.
 
void append (PRIMITIVE datum)
 Inserts one datum into the panel, possibly triggering allocation of a new panel.
 
void extend (const PRIMITIVE *ptr, size_t size)
 Inserts an entire array into the panel(s), possibly triggering allocation of a new panel.
 
PRIMITIVE & append_and_get_ref (PRIMITIVE datum)
 Like append, but the type signature returns the reference to PRIMITIVE.
 
void concatenate (PRIMITIVE *external_pointer) const noexcept
 Copies and concatenates all accumulated data from multiple panels to one contiguously allocated external_pointer.
 
void move_to (PRIMITIVE *to_ptr) noexcept
 Moves all accumulated data from multiple panels to one contiguously allocated external_pointer. The panels are deleted, and a new #ptr is allocated.
 
void concatenate_from (PRIMITIVE *external_pointer, size_t to, size_t from) const noexcept
 Copies and concatenates all accumulated data from multiple panels to one contiguously allocated external_pointer.
 
void append (PRIMITIVE *external_pointer, size_t offset, size_t from, int64_t length) const noexcept
 Copies data from a panel to one contiguously allocated external_pointer.
 

Static Public Member Functions

static GrowableBuffer< PRIMITIVE > empty (const BuilderOptions &options)
 Creates an empty GrowableBuffer.
 
static GrowableBuffer< PRIMITIVE > empty (const BuilderOptions &options, int64_t minreserve)
 Creates an empty GrowableBuffer with a minimum reservation.
 
static GrowableBuffer< PRIMITIVE > zeros (const BuilderOptions &options, int64_t length)
 Creates a GrowableBuffer in which all elements are initialized to 0.
 
static GrowableBuffer< PRIMITIVE > full (const BuilderOptions &options, PRIMITIVE value, int64_t length)
 Creates a GrowableBuffer in which all elements are initialized to a given value.
 
static GrowableBuffer< PRIMITIVE > arange (const BuilderOptions &options, int64_t length)
 Creates a GrowableBuffer in which the elements are initialized to numbers counting from 0 to length.
 
template<typename TO_PRIMITIVE >
static GrowableBuffer< TO_PRIMITIVE > copy_as (const GrowableBuffer< PRIMITIVE > &other)
 Takes a (possibly multi-panels) GrowableBuffer<PRIMITIVE> and makes another (one panel) GrowableBuffer<TO_PRIMITIVE>.
 

Detailed Description

template<typename PRIMITIVE>
class awkward::GrowableBuffer< PRIMITIVE >

Discontiguous, one-dimensional buffer (which consists of multiple contiguous, one-dimensional panels) that can grow indefinitely by calling append.

Configured by BuilderOptions, the buffer starts by reserving initial slots. When the number of slots used reaches the number reserved, a new panel is allocated that is resize times larger.

When ArrayBuilder::to_buffers is called, these buffers are copied to the new Content array.

Constructor & Destructor Documentation

◆ GrowableBuffer() [1/3]

template<typename PRIMITIVE >
GrowableBuffer ( const BuilderOptions & options,
std::unique_ptr< PRIMITIVE[]> ptr,
int64_t length,
int64_t reserved )
inline

Creates a GrowableBuffer from a full set of parameters.

Parameters
optionsInitial size configuration for building a panel.
ptrReference-counted pointer to the array buffer.
lengthCurrently used number of elements.
reservedCurrently allocated number of elements.

Although the length increments every time append is called, it is always less than or equal to #reserved because of allocations of new panels.

◆ GrowableBuffer() [2/3]

template<typename PRIMITIVE >
GrowableBuffer ( const BuilderOptions & options)
inline

Creates a GrowableBuffer by allocating a new buffer, taking an options #reserved from options.

Parameters
optionsInitial size configuration for building a panel.

◆ GrowableBuffer() [3/3]

template<typename PRIMITIVE >
GrowableBuffer ( GrowableBuffer< PRIMITIVE > && other)
inlinenoexcept

Move constructor.

panel_ is move-only.

Member Function Documentation

◆ append() [1/2]

template<typename PRIMITIVE >
void append ( PRIMITIVE * external_pointer,
size_t offset,
size_t from,
int64_t length ) const
inlinenoexcept

Copies data from a panel to one contiguously allocated external_pointer.

◆ append() [2/2]

template<typename PRIMITIVE >
void append ( PRIMITIVE datum)
inline

Inserts one datum into the panel, possibly triggering allocation of a new panel.

This increases the length by 1; if the new length is larger than #reserved, a new panel will be allocated.

◆ append_and_get_ref()

template<typename PRIMITIVE >
PRIMITIVE & append_and_get_ref ( PRIMITIVE datum)
inline

Like append, but the type signature returns the reference to PRIMITIVE.

◆ arange()

template<typename PRIMITIVE >
static GrowableBuffer< PRIMITIVE > arange ( const BuilderOptions & options,
int64_t length )
inlinestatic

Creates a GrowableBuffer in which the elements are initialized to numbers counting from 0 to length.

Parameters
optionsInitial size configuration for building a panel.
lengthThe number of elements to initialize (and the GrowableBuffer's initial length).

This is similar to NumPy's arange.

◆ clear()

template<typename PRIMITIVE >
void clear ( )
inline

Discards accumulated data, the #reserved returns to options.initial(), and a new #ptr is allocated.

◆ concatenate()

template<typename PRIMITIVE >
void concatenate ( PRIMITIVE * external_pointer) const
inlinenoexcept

Copies and concatenates all accumulated data from multiple panels to one contiguously allocated external_pointer.

◆ concatenate_from()

template<typename PRIMITIVE >
void concatenate_from ( PRIMITIVE * external_pointer,
size_t to,
size_t from ) const
inlinenoexcept

Copies and concatenates all accumulated data from multiple panels to one contiguously allocated external_pointer.

◆ copy_as()

template<typename PRIMITIVE >
template<typename TO_PRIMITIVE >
static GrowableBuffer< TO_PRIMITIVE > copy_as ( const GrowableBuffer< PRIMITIVE > & other)
inlinestatic

Takes a (possibly multi-panels) GrowableBuffer<PRIMITIVE> and makes another (one panel) GrowableBuffer<TO_PRIMITIVE>.

Used to change the data type of buffer content from PRIMITIVE to TO_PRIMITIVE for building arrays.

◆ empty() [1/2]

template<typename PRIMITIVE >
static GrowableBuffer< PRIMITIVE > empty ( const BuilderOptions & options)
inlinestatic

Creates an empty GrowableBuffer.

Parameters
optionsInitial size configuration for building a panel.

◆ empty() [2/2]

template<typename PRIMITIVE >
static GrowableBuffer< PRIMITIVE > empty ( const BuilderOptions & options,
int64_t minreserve )
inlinestatic

Creates an empty GrowableBuffer with a minimum reservation.

Parameters
optionsInitial size configuration for building a panel.
minreserveThe initial reservation will be the maximum of minreserve and initial.

◆ extend()

template<typename PRIMITIVE >
void extend ( const PRIMITIVE * ptr,
size_t size )
inline

Inserts an entire array into the panel(s), possibly triggering allocation of a new panel.

If the size is larger than the empty slots in the current panel, then, first, the empty slots are filled and then a new panel will be allocated for the rest of the array elements.

◆ full()

template<typename PRIMITIVE >
static GrowableBuffer< PRIMITIVE > full ( const BuilderOptions & options,
PRIMITIVE value,
int64_t length )
inlinestatic

Creates a GrowableBuffer in which all elements are initialized to a given value.

Parameters
optionsInitial size configuration for building a panel.
valueThe initialization value.
lengthThe number of elements to initialize (and the GrowableBuffer's initial length).

This is similar to NumPy's full.

◆ last()

template<typename PRIMITIVE >
PRIMITIVE last ( ) const
inline

Last element in last panel.

◆ length()

template<typename PRIMITIVE >
size_t length ( ) const
inline

Currently used number of elements.

Although the length increments every time append is called, it is always less than or equal to #reserved because of allocations of new panels.

◆ move_to()

template<typename PRIMITIVE >
void move_to ( PRIMITIVE * to_ptr)
inlinenoexcept

Moves all accumulated data from multiple panels to one contiguously allocated external_pointer. The panels are deleted, and a new #ptr is allocated.

◆ nbytes()

template<typename PRIMITIVE >
size_t nbytes ( ) const
inline

Currently used number of bytes.

◆ options()

template<typename PRIMITIVE >
const BuilderOptions & options ( ) const
inline

Return options of this GrowableBuffer.

◆ zeros()

template<typename PRIMITIVE >
static GrowableBuffer< PRIMITIVE > zeros ( const BuilderOptions & options,
int64_t length )
inlinestatic

Creates a GrowableBuffer in which all elements are initialized to 0.

Parameters
optionsInitial size configuration for building a panel.
lengthThe number of elements to initialize (and the GrowableBuffer's initial length).

This is similar to NumPy's zeros.


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