AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
|
Provides a generic multi-component array container. More...
#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.5.0/src/axom/core/Array.hpp>
Public Member Functions | |
virtual | ~Array () |
Native Storage Array Constructors | |
Array (IndexType num_tuples, IndexType num_components=1, IndexType capacity=0) | |
Constructs an Array instance with the given number of tuples. More... | |
External Storage Array Constructors | |
Array (T *data, IndexType num_tuples, IndexType num_components=1, IndexType capacity=0) | |
Constructs an Array instance with the given number of tuples from an external data buffer. More... | |
Array tuple access operators | |
T & | operator() (IndexType pos, IndexType component=0) |
Accessor, returns a reference to the given component of the specified tuple. More... | |
const T & | operator() (IndexType pos, IndexType component=0) const |
T & | operator[] (IndexType idx) |
Accessor, returns a reference to the given value. More... | |
const T & | operator[] (IndexType idx) const |
T * | getData () |
Return a pointer to the array of data. More... | |
const T * | getData () const |
Array methods to modify the data. | |
void | fill (const T &value) |
Set all the values of the array. More... | |
void | append (const T &value) |
Append a value to the end of the array. More... | |
void | append (const T *tuples, IndexType n) |
Append tuples to the end of the array. More... | |
void | set (const T *tuples, IndexType n, IndexType pos) |
Modify the values of existing tuples. More... | |
void | insert (const T &value, IndexType pos) |
Insert a tuple into the array at the given position. More... | |
void | insert (const T *tuples, IndexType n, IndexType pos) |
Insert tuples into the array at the given position. More... | |
void | emplace (IndexType n, IndexType pos, const T &value=T()) |
Insert multiple copies of the same value at the given position. More... | |
Array methods to query and set attributes | |
IndexType | capacity () const |
Return the number of tuples allocated for the data array. More... | |
void | reserve (IndexType capacity) |
Increase the capacity. Does nothing if the new capacity is less than the current capacity. More... | |
void | shrink () |
Shrink the capacity to be equal to the size. More... | |
bool | empty () const |
Returns true iff the Array stores no elements. More... | |
IndexType | size () const |
Return the number of tuples stored in the data array. More... | |
void | resize (IndexType new_num_tuples) |
Update the number of tuples stored in the data array. More... | |
double | getResizeRatio () const |
Get the ratio by which the capacity increases upon dynamic resize. More... | |
void | setResizeRatio (double ratio) |
Set the ratio by which the capacity increases upon dynamic resize. More... | |
IndexType | numComponents () const |
Return the number of components per tuple. More... | |
bool | isExternal () const |
Return true iff the external buffer constructor was called. More... | |
virtual bool | isInSidre () const |
Return true iff a sidre constructor was called. More... | |
Static Public Attributes | |
static constexpr double | DEFAULT_RESIZE_RATIO = 2.0 |
static constexpr IndexType | MIN_DEFAULT_CAPACITY = 32 |
Protected Member Functions | |
Array () | |
Default constructor supports infrastructure in subclasses. More... | |
void | initialize (IndexType num_tuples, IndexType num_components, IndexType capacity) |
Initialize an Array instance with the given number of tuples. More... | |
T * | reserveForInsert (IndexType n, IndexType pos) |
Make space for a subsequent insertion into the array. More... | |
virtual void | updateNumTuples (IndexType new_num_tuples) |
Update the number of tuples. More... | |
virtual void | setCapacity (IndexType new_capacity) |
Set the number of tuples allocated for the data array. More... | |
virtual void | dynamicRealloc (IndexType new_num_tuples) |
Reallocates the data array when the size exceeds the capacity. More... | |
Array (const Array &)=delete | |
Array & | operator= (const Array &)=delete |
Array (const Array &&)=delete | |
Array & | operator= (const Array &&)=delete |
Internal bounds-checking routines | |
bool | inBounds (IndexType pos, IndexType component) const |
Test if pos and component are within bounds. More... | |
bool | inBounds (IndexType idx) const |
Test if idx is within bounds. More... | |
Protected Attributes | |
T * | m_data |
IndexType | m_num_tuples |
IndexType | m_capacity |
IndexType | m_num_components |
double | m_resize_ratio |
bool const | m_is_external |
Provides a generic multi-component array container.
The Array class provides a generic multi-component array container with dynamic re-allocation and insertion. Each element in the array is a tuple consisting of 1 or more components, which are stored contiguously.
Depending on which constructor is used, the Array object can have two different underlying storage types:
Native Storage
When using native storage, the Array object manages all memory. Typically, the Array object will allocate extra space to facilitate the insertion of new elements and minimize the number of reallocations. The actual capacity of the array (i.e., total number of tuples that the Array can hold) can be queried by calling the capacity() function. When allocated memory is used up, inserting a new element triggers a re-allocation. At each re-allocation, extra space is allocated according to the resize_ratio parameter, which is set to 2.0 by default. To return all extra memory, an application can call shrink()
.
External Storage
An Array object may be constructed from an external, user-supplied buffer consisting of the given number of tuples and specified number of components per tuple. In this case, the Array object does not own the memory. Instead, the Array object makes a shallow copy of the pointer.
reserve()
when the number of nodes is known a priori, or opt to use a constructor that takes an actual size and capacity when possible.T | the type of the values to hold. |
axom::Array< T >::Array | ( | IndexType | num_tuples, |
IndexType | num_components = 1 , |
||
IndexType | capacity = 0 |
||
) |
Constructs an Array instance with the given number of tuples.
[in] | num_tuples | the number of tuples the Array holds. |
[in] | num_components | the number of values per tuple. If not specified defaults to 1. |
[in] | capacity | the number of tuples to allocate space for. |
axom::Array< T >::Array | ( | T * | data, |
IndexType | num_tuples, | ||
IndexType | num_components = 1 , |
||
IndexType | capacity = 0 |
||
) |
Constructs an Array instance with the given number of tuples from an external data buffer.
[in] | data | the external data this Array will wrap. |
[in] | num_tuples | the number of tuples in the Array. |
[in] | num_components | the number of values per tuple. If not specified defaults to 1. |
[in] | capacity | the capacity of the external buffer. |
|
virtual |
Destructor. Frees the associated buffer unless the memory is external.
Reimplemented in axom::sidre::Array< T >.
|
protected |
Default constructor supports infrastructure in subclasses.
|
protecteddelete |
|
protecteddelete |
|
inline |
Accessor, returns a reference to the given component of the specified tuple.
[in] | pos | the tuple to query. |
[in] | component | the component to return. |
|
inline |
|
inline |
Accessor, returns a reference to the given value.
[in] | idx | the position of the value to return. |
|
inline |
|
inline |
Return a pointer to the array of data.
Referenced by axom::mint::ConnectivityArray< TYPE >::getValuePtr(), and axom::mint::ConnectivityArray< TYPE >::operator[]().
|
inline |
|
inline |
Set all the values of the array.
[in] | value | the value to set to. |
|
inline |
Append a value to the end of the array.
[in] | value | the value to append. |
Referenced by axom::mint::ConnectivityArray< TYPE >::appendM().
|
inline |
Append tuples to the end of the array.
[in] | tuples | the tuples to append. |
[in] | n | the number of tuples to append. |
|
inline |
Modify the values of existing tuples.
[in] | tuples | the new tuples to write. |
[in] | n | the number of tuples to write. |
[in] | pos | the position at which to begin writing. |
Referenced by axom::mint::ConnectivityArray< TYPE >::set(), and axom::mint::ConnectivityArray< TYPE >::setM().
|
inline |
Insert a tuple into the array at the given position.
[in] | value | the value to insert. |
[in] | pos | the position at which to insert. |
Referenced by axom::mint::ConnectivityArray< TYPE >::insertM().
|
inline |
Insert tuples into the array at the given position.
[in] | tuples | the tuples to insert. |
[in] | n | the number of tuples to insert. |
[in] | pos | the position at which to begin the insertion. |
|
inline |
Insert multiple copies of the same value at the given position.
[in] | n | the number of tuples to insert. |
[in] | pos | the position to insert at. |
[in] | value | the value for each component of the new tuples. If not specified defaults to the default value of T (zero for most numeric types). |
|
inline |
Return the number of tuples allocated for the data array.
Referenced by axom::mint::ConnectivityArray< TYPE >::getIDCapacity(), and axom::mint::ConnectivityArray< TYPE >::reserve().
|
inline |
Increase the capacity. Does nothing if the new capacity is less than the current capacity.
[in] | capacity | the new number of tuples to allocate. |
Referenced by axom::mint::ConnectivityArray< TYPE >::reserve().
|
inline |
Shrink the capacity to be equal to the size.
Referenced by axom::mint::ConnectivityArray< TYPE >::shrink().
|
inline |
Returns true iff the Array stores no elements.
Referenced by axom::mint::ConnectivityArray< TYPE >::empty().
|
inline |
Return the number of tuples stored in the data array.
Referenced by axom::mint::ConnectivityArray< TYPE >::getNumberOfIDs(), and axom::mint::ConnectivityArray< TYPE >::getNumberOfValues().
|
inline |
Update the number of tuples stored in the data array.
Referenced by axom::mint::ConnectivityArray< TYPE >::resize().
|
inline |
Get the ratio by which the capacity increases upon dynamic resize.
Referenced by axom::mint::ConnectivityArray< TYPE >::getResizeRatio().
|
inline |
Set the ratio by which the capacity increases upon dynamic resize.
[in] | ratio | the new resize ratio. |
Referenced by axom::mint::ConnectivityArray< TYPE >::setResizeRatio().
|
inline |
Return the number of components per tuple.
Referenced by axom::mint::ConnectivityArray< TYPE >::ConnectivityArray().
|
inline |
Return true iff the external buffer constructor was called.
Referenced by axom::mint::RectilinearMesh::isExternal(), and axom::mint::ConnectivityArray< TYPE >::isExternal().
|
inlinevirtual |
Return true iff a sidre constructor was called.
Reimplemented in axom::sidre::Array< T >.
Referenced by axom::mint::ConnectivityArray< TYPE >::isInSidre().
|
inlineprotected |
Initialize an Array instance with the given number of tuples.
[in] | num_tuples | the number of tuples the Array holds. |
[in] | num_components | the number of values per tuple. If not specified defaults to 1. |
[in] | capacity | the number of tuples to allocate space for. |
Referenced by axom::sidre::Array< T >::Array().
|
inlineprotected |
Make space for a subsequent insertion into the array.
[in] | n | the number of tuples to insert. |
[in] | pos | the position at which to begin the insertion. |
|
inlineprotectedvirtual |
Update the number of tuples.
[in] | new_num_tuples | the new number of tuples. |
Reimplemented in axom::sidre::Array< T >.
|
inlineprotectedvirtual |
Set the number of tuples allocated for the data array.
[in] | capacity | the new number of tuples to allocate. |
Reimplemented in axom::sidre::Array< T >.
|
inlineprotectedvirtual |
Reallocates the data array when the size exceeds the capacity.
[in] | new_num_tuples | the number of tuples which exceeds the current capacity. |
Reimplemented in axom::sidre::Array< T >.
|
inlineprotected |
Test if pos and component are within bounds.
|
inlineprotected |
Test if idx is within bounds.
|
protecteddelete |
|
protecteddelete |
|
static |
|
static |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by axom::sidre::Array< T >::dynamicRealloc().
|
protected |