93# ifndef TPL_MEMARRAY_H
94# define TPL_MEMARRAY_H
137 template <
typename T>
189 const size_t mask =
dim - 1;
191 for (
size_t i = 0; i <
dim; ++i)
227 const size_t mask =
dim - 1;
228 for (
int i = 0; i <
newsz; ++i)
281 static_assert(std::is_copy_constructible_v<T>,
282 "No copy constructor for T");
283 static_assert(std::is_move_constructible_v<T>,
284 "No move constructor for T");
285 static_assert(std::is_copy_assignable_v<T>,
286 "No copy assign for T");
287 static_assert(std::is_move_assignable_v<T>,
288 "No move assign for T");
305 std::swap(
ptr, a.ptr);
306 std::swap(
dim, a.dim);
316 for (
int i = 0; i <
dim; ++i)
337 for (
int i = 0; i < a.
n; ++i)
393 ptr[
n] = std::forward<T>(item);
433 ptr[0] = std::forward<T>(item);
469 return put(std::forward<T>(item));
483 return push(std::forward<T>(item));
511 for (
size_t i = 0; i <
n; ++i)
543 size_t k =
log2(cap);
547 for (
size_t i = 0; i <
n; ++i)
561 const long idx =
n - i;
563 <<
"MemArray::get(): deleted more entries than capacity";
576 const long idx =
n - i;
611 for (
size_t i = 0, j =
n - 1; i < j; ++i, --j)
612 std::swap(
ptr[i],
ptr[j]);
649 template <
class Operation>
653 for (
int i = 0; i <
n; i++)
661 template <
class Operation>
668 template <
class Operation>
675 template <
class Operation>
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
DRY (Don't Repeat Yourself) utilities and macros.
Iterator traits and STL-compatible iterator wrappers.
General utility functions and helpers.
Iterator wrapper for C++ raw arrays and circular buffers.
Utility functions for array manipulation.
Iterator wrapper for C++ raw arrays.
Simple, scalable and fast dynamic array.
T & put(const T &item)
Put a copy of item at the end of sequence.
T & operator()(const size_t i) const noexcept
MemArray(const MemArray &a)
Construct a copy of a
void reserve(const size_t cap)
Reserves cap cells into the array.
void open_gap(size_t pos=0, size_t num_entries=1)
T & push(T &&item)
Push a copy of item at the beginning of sequence.
bool traverse(Operation &operation)
Traverse all the elements from index 0 to n - 1 and execute operation on each on them.
bool contract(const size_t first=0)
Test if n is lesser than contract_threshold and eventually contract the array half long and copies it...
size_t size() const noexcept
Return the number of elements.
void putn(const size_t more)
Reserve more additional logical slots in the array.
T get_ne(const size_t i=1) noexcept
T & first() const
Return a modifiable reference to the first element.
T & access(const size_t i) const noexcept
Return a modifiable reference to the ith element.
size_t contract_threshold
MemArray & append(const MemArray &a)
MemArray & operator=(const MemArray &a)
Assign by copy a to this
void empty_and_release()
Empty the array and release all memory.
static constexpr size_t Min_Dim
MemArray(MemArray &&a) noexcept
Construct an array moved of rvalue a
void empty()
Empty the container. The array is not contracted.
void allocate()
Allocate memory for the current dimension.
bool traverse(Operation &&operation) const
T * get_ptr() const noexcept
Return the current base of array.
bool expand(const size_t first=0)
Test is array is full and if affrimative, then expand the array twice as long and copy the content by...
void init_dim(size_t d) noexcept
Initialize the dimension of the array to d or to the next two power if d is not a two power.
constexpr size_t capacity() const noexcept
The type of element of array.
T & last() const
Return a modifiable reference to the last element.
bool is_valid() const noexcept
void close_gap(size_t pos, size_t num_entries=1)
bool is_empty() const noexcept
Return true is the array is empty.
bool traverse(Operation &&operation)
T pop()
pop() the most recently pushed item
MemArray & reverse()
Reverse the order of items in array.
const size_t & get_dim() const noexcept
Return the current dimension of array.
T get(const size_t i=1)
Remove i elements from the end.
MemArray(size_t __dim=Min_Dim)
Construct an array con capacity equal or gre+ater than __dim.
void swap(MemArray &a) noexcept
Swap in constant time this with a
bool traverse(Operation &operation) const
T & operator[](const size_t i) const
Return a reference to the ith element.
T & put(T &&item)
Move item at the end of sequence.
T & push(const T &item)
Push a copy of item at the beginning of sequence.
T remove_first()
Remove first item. Gap is closed.
MemArray & operator=(MemArray &&a) noexcept
Assign by moving a to this
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log2_function > > log2(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
void open_gap(Tarray &ptr, size_t n, size_t pos=0, size_t num_entries=1)
Open a gap in an array by shifting elements right.
bool is_power_of_2(unsigned long x)
Taken from http://stackoverflow.com/questions/3638431/determine-if-an-int-is-a-power-of-2-or-not-in-a...
void close_gap(T *ptr, size_t n, size_t pos, size_t num_entries=1)
Close a gap in an array by shifting elements left.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Simple iterator on elements of array.
Iterator(const MemArray< T > &a) noexcept
Construct an iterator on array a