187 const size_t mask =
dim - 1;
189 for (
size_t i = 0; i <
dim; ++i)
225 const size_t mask =
dim - 1;
226 for (
int i = 0; i <
newsz; ++i)
286 static_assert(std::is_move_constructible_v<T>,
"T must be move constructible");
287 static_assert(std::is_move_assignable_v<T>,
"T must be move assignable");
304 std::swap(
ptr, a.ptr);
305 std::swap(
dim, a.dim);
312 requires(std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T>)
316 for (
int i = 0; i <
n; ++i)
329 requires(std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T>)
337 for (
size_t i = 0; i < a.n; ++i)
395 requires std::is_copy_assignable_v<T>
412 ptr[
n] = std::forward<T>(item);
434 requires std::is_copy_assignable_v<T>
451 ptr[0] = std::forward<T>(item);
481 requires std::is_copy_assignable_v<T>
491 return put(std::forward<T>(item));
496 requires std::is_copy_assignable_v<T>
506 return push(std::forward<T>(item));
534 for (
size_t i = 0; i <
n; ++i)
545 requires std::is_copy_assignable_v<T>
567 size_t k =
log2(cap);
571 for (
size_t i = 0; i <
n; ++i)
585 const long idx =
n - i;
599 const long idx =
n - i;
643 for (
size_t i = 0, j =
n - 1; i < j; ++i, --j)
644 std::swap(
ptr[i],
ptr[j]);
681 template <
class Operation>
685 for (
int i = 0; i <
n; i++)
693 template <
class Operation>
700 template <
class Operation>
707 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 & operator()(const size_t i) const noexcept
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
void clear() noexcept
Alias for empty().
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.
T & append(const T &item)
size_t contract_threshold
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 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...
MemArray(const MemArray &a)
Construct a copy of a
T & push(const T &item)
Push a copy of item at the beginning of sequence.
MemArray & append(const MemArray &a)
MemArray(size_t _dim=Min_Dim)
Construct an array con capacity equal or greater than _dim.
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.
MemArray & operator=(const MemArray &a)
Assign by copy a to this
T & insert(const T &item)
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
void empty() noexcept
Empties the container.
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.
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 & put(const T &item)
Put a copy of item at the end of sequence.
T remove_first()
Remove the 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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.
Simple iterator on elements of array.
Iterator(const MemArray< T > &a) noexcept
Construct an iterator on array a