#include <tpl_memArray.H>
Inheritance diagram for Aleph::MemArray< T >:Classes | |
| struct | Iterator |
Public Types | |
| using | Item_Type = T |
Public Member Functions | |
| T * | get_ptr () const noexcept |
| Return the current base of array. | |
| const size_t & | get_dim () const noexcept |
| Return the current dimension of array. | |
| size_t | capacity () const noexcept |
| The type of element of array. More... | |
| size_t | size () const noexcept |
| Return the number of elements. | |
| bool | is_empty () const noexcept |
Return true is the array is empty. | |
| MemArray (size_t __dim=Min_Dim) | |
| void | swap (MemArray &a) noexcept |
Swap in constant time this with a | |
| MemArray (const MemArray &a) | |
Construct a copy of a | |
| MemArray (MemArray &&a) noexcept | |
Construct a array moved of rvalue a | |
| MemArray & | operator= (const MemArray &a) |
Assign by copy a to this | |
| MemArray & | operator= (MemArray &&a) noexcept |
Assign by moving a to this | |
| void | empty () |
| Empty the container. The array is not contracted. | |
| void | empty_and_release () |
| Empty the array and release all memory. | |
| T & | put (const T &item) |
| T & | put (T &&item) |
| T & | push (const T &item) |
| T & | push (T &&item) |
| T & | top () const |
| T | remove_first () |
| Remove first item. Gap is closed. | |
| T | pop () |
| pop() the most recently pushed item | |
| T & | append (T &item) |
| T & | append (T &&item) |
| T & | insert (T &item) |
| T & | insert (T &&item) |
| void | putn (const size_t more) |
| MemArray & | append (const MemArray &a) |
| void | reserve (const size_t cap) |
| T | get (size_t i=1) |
| T | get_ne (size_t i=1) noexcept |
| T | remove_last () |
| T & | last () const |
| Return a modifiable reference to the last element. | |
| T & | first () const |
| Return a modifiable reference to the first element. | |
| T & | get_first () const |
| T & | get_last () const |
| MemArray & | reverse () |
| Reverse the order of items in array. | |
| T & | access (const size_t i) const noexcept |
| T & | operator[] (const size_t i) const |
| T & | operator() (const size_t i) const noexcept |
| template<class Operation > | |
| bool | traverse (Operation &operation) |
| template<class Operation > | |
| bool | traverse (Operation &operation) const |
| template<class Operation > | |
| bool | traverse (Operation &&operation) const |
| template<class Operation > | |
| bool | traverse (Operation &&operation) |
| bool | is_valid () const noexcept |
Public Attributes | |
| size_t | contract_threshold |
Static Public Attributes | |
| static constexpr size_t | Min_Dim = 4 |
Protected Member Functions | |
| void | allocate () |
| Allocate memory for the current dimension. | |
| bool | expand (const size_t first=0) |
| bool | contract (const size_t first=0) |
| void | init_dim (size_t d) noexcept |
Protected Attributes | |
| T * | ptr = nullptr |
| size_t | dim = Min_Dim |
| size_t | n = 0 |
Simple, scalable and fast dynamic array.
MemArray implement a totally sequential dynamic array. That is, conditioned to memory availability, all the array is stored in a contiguous chunk of memory. So, the access is direct and with exactly the same cost of accessing a normal array.
The array allows to insert and remove elements. These operation are conceived by the ends. The number of stored elements is called n.
The allocation technique obeys to "buddy system"; that is, the exact dimension of array always is an exact two power.
When the array is full, a new chunk twice as long is allocated and the current entries are moved (by move semantic if available).
When the number of entries descend to a contract_threshold the array is half long contracted.
|
inline |
Construct an array con capacicity equal or greater than __dim.
| [in] | __dim | proposed dimension of arraym which could be adjusted to the next two power greater than __dim |
| bad_alloc | si no hay suficiente memoria. |
|
inlinenoexcept |
Return a modifiable reference to the ith element. No bound check is performed
Here is the caller graph for this function:
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Here is the caller graph for this function:
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inlinenoexcept |
The type of element of array.
Return the capacity of array (its dimension)
Here is the caller graph for this function:
|
inlineprotected |
Test if n is lesser than contract_threshold and eventually contract the array half long and copies its content.
contract(first) first testes n with contract_threshold. If it is lesser, then a new array half as long is allocated and the n elements from first are copied.
| [in] | first | index of first element |
true if the array is reallocated
Here is the caller graph for this function:
|
inlineprotected |
Test is array is full and if affrimative, then expand the array twice as long and copy the content by swapping.
This method first allocates a chunck of 2*dim and then copies from first index the n contained entries to the new chunck.
| [in] | first | index where is found the first item of array |
true if the array was full and then a new twice as long was allocated | bad_alloc | if there is no enough memory |
Here is the caller graph for this function:
|
inline |
Remove i elements from the end. Return the value of the last removed element
Here is the caller graph for this function:
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return a reference to the ith element. Throws out_of_range if i is out of range
|
inline |
Push a copy of item at the begining of sequence. The array expands if this is already full
Here is the caller graph for this function:
|
inline |
Push a copy of item at the begining of sequence. The array expands if this is already full
|
inline |
Put a copy of item at the end of sequence. The array expands if this is already full
Here is the caller graph for this function:
|
inline |
Move item at the end of sequence. The array expands if this is already full
|
inline |
Put n cells into the array.
putn(more) is functionally equivalent to perform more puts of T() in constant time. The idea is to reserve enough space for later use.
| [in] | n | number of cells to reserve |
| bad_alloc | if there is no enough memory |
Here is the caller graph for this function:
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Here is the caller graph for this function:
|
inline |
Reserves cap cells into the array.
| [in] | cap | new dimension |
| bad_alloc | if there is no enough memory |
Here is the caller graph for this function:
|
inline |
Traverse all the elements from index 0 to n - 1 and execute operation on each on them.
| [in] | operation | to be performed on each element |
true if operation was executed on all elements; false otherwise.
Here is the caller graph for this function:
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.