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 BuilderOptions & | options () 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>. | |
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.
|
inline |
Creates a GrowableBuffer from a full set of parameters.
options | Initial size configuration for building a panel. |
ptr | Reference-counted pointer to the array buffer. |
length | Currently used number of elements. |
reserved | Currently 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.
|
inline |
Creates a GrowableBuffer by allocating a new buffer, taking an options #reserved from options.
options | Initial size configuration for building a panel. |
|
inlinenoexcept |
Move constructor.
panel_ is move-only.
|
inlinenoexcept |
Copies data from a panel to one contiguously allocated external_pointer
.
|
inline |
|
inline |
Like append, but the type signature returns the reference to PRIMITIVE
.
|
inlinestatic |
Creates a GrowableBuffer in which the elements are initialized to numbers counting from 0
to length
.
options | Initial size configuration for building a panel. |
length | The number of elements to initialize (and the GrowableBuffer's initial length). |
This is similar to NumPy's arange.
|
inline |
Discards accumulated data, the #reserved returns to options.initial(), and a new #ptr is allocated.
|
inlinenoexcept |
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated external_pointer
.
|
inlinenoexcept |
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated external_pointer
.
|
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.
|
inlinestatic |
Creates an empty GrowableBuffer.
options | Initial size configuration for building a panel. |
|
inlinestatic |
Creates an empty GrowableBuffer with a minimum reservation.
options | Initial size configuration for building a panel. |
minreserve | The initial reservation will be the maximum of minreserve and initial . |
|
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.
|
inlinestatic |
Creates a GrowableBuffer in which all elements are initialized to a given value.
options | Initial size configuration for building a panel. |
value | The initialization value. |
length | The number of elements to initialize (and the GrowableBuffer's initial length). |
This is similar to NumPy's full.
|
inline |
Last element in last panel.
|
inline |
|
inlinenoexcept |
Moves all accumulated data from multiple panels to one contiguously allocated external_pointer
. The panels are deleted, and a new #ptr is allocated.
|
inline |
Currently used number of bytes.
|
inline |
Return options of this GrowableBuffer.
|
inlinestatic |
Creates a GrowableBuffer in which all elements are initialized to 0
.
options | Initial size configuration for building a panel. |
length | The number of elements to initialize (and the GrowableBuffer's initial length). |
This is similar to NumPy's zeros.