45#ifndef TPL_ARRAYSTACK_H
46#define TPL_ARRAYSTACK_H
103 :
array(std::move(s.array))
141 return array.put(data);
152 return array.put(std::forward<T>(data));
196 return array.get_ne(1);
227 return array.first();
232 return array.first();
246 const size_t sz =
array.size();
248 return array.access(sz - i - 1);
253 const size_t sz =
array.size();
255 return array(sz - i - 1);
288 template <
class Operation>
295 template <
class Operation>
302 template <
class Operation>
309 template <
class Operation>
346 template <
typename T>
379 std::unique_ptr<T[]>
tmp(
new T[s.
dim]);
380 for (
size_t i = 0; i <
head; ++i)
390 std::swap(
array, s.array);
391 std::swap(
head, s.head);
392 std::swap(
dim, s.dim);
424 T &
push(
const T & data)
noexcept(std::is_nothrow_copy_assignable_v<T>)
436 T &
push(
T && data)
noexcept(std::is_nothrow_move_assignable_v<T>)
444 T &
append(
const T & data)
noexcept(std::is_nothrow_copy_assignable_v<T>)
450 T &
append(
T && data)
noexcept(std::is_nothrow_move_assignable_v<T>)
452 return push(std::forward<T>(data));
456 T &
insert(
const T & data)
noexcept(std::is_nothrow_copy_assignable_v<T>)
462 T &
insert(
T && data)
noexcept(std::is_nothrow_move_assignable_v<T>)
464 return push(std::forward<T>(data));
497 const auto count =
static_cast<size_t>(n);
535 T &
top(
const size_t i)
noexcept
541 const T &
top(
const size_t i)
const noexcept
570 template <
class Operation>
573 for (
size_t i = 0; i <
head; i++)
581 template <
class Operation>
588 template <
class Operation>
595 template <
class Operation>
Variadic constructor macros for containers.
Container traversal and functional operation mixins.
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_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Core header for the Aleph-w library.
Iterator on the items of a stack.
typename MemArray< T >::Iterator Base
Iterator(const ArrayStack< T > &s)
Initialize an iterator on stack s
Stack implemented with simple dynamic array and with bounds verification.
const T & get_last() const
void swap(ArrayStack &s) noexcept
Swap this with s
bool traverse(Operation &&operation=Operation())
T & insert(const T &data)
void empty() noexcept
Empty the stack.
ArrayStack(const ArrayStack &s)
Copy constructor.
ArrayStack(size_t dim=4)
The type of element.
T & top()
Return a modifiable reference to youngest element of stack (called the top)
bool is_empty() const noexcept
Return true if stack is empty.
ArrayStack & operator=(const ArrayStack &s)
Assign by copy s to this
bool traverse(Operation &operation)
Traverse all the items of stack from the youngest to oldest and conditionally performs an operation.
size_t size() const noexcept
Return the number of elements stored in the stack.
const T & base() const noexcept
T & pushn(const size_t &n=1)
Push n cells into the stack.
T & append(const T &data)
bool traverse(Operation &operation) const
T & base() noexcept
Return a modifiable reference to first element of array.
T popn(size_t n)
Extract in constant time the n more recently inserted elements of stack.
const T & top(size_t i) const
void clear() noexcept
Empties the container.
T & top(size_t i)
Return a modifiable reference to the element located at i positions from top.
T pop()
Extract the last more recently inserted element.
bool traverse(Operation &&operation=Operation()) const
T & push(const T &data)
Push into stack a copy of data
ArrayStack(ArrayStack &&s) noexcept
Move constructor.
size_t capacity() const noexcept
Return the internal capacity.
T & push(T &&data)
Push into stack data
Iterator wrapper for C++ raw arrays.
Iterator on the items of a stack.
Iterator(const FixedStack< T > &s)
T & base() noexcept
Return the internal array base.
bool traverse(Operation &&operation=Operation()) const
FixedStack & operator=(const FixedStack &s)
Assign by copy s to this
size_t size() const noexcept
Return the number of elements stored in the stack.
const T & top() const noexcept
T & pushn(const size_t &n=1) noexcept
Push in constant time nspaces into stack.
const T & get_last() const noexcept
T & insert(T &&data) noexcept(std::is_nothrow_move_assignable_v< T >)
T popn(const int &n) noexcept
Perform in constant time n pops.
bool traverse(Operation &&operation=Operation())
T & append(T &&data) noexcept(std::is_nothrow_move_assignable_v< T >)
bool is_empty() const noexcept
Return true if stack is empty.
bool traverse(Operation &operation)
Traverse all the items of stack from the youngest to oldest and conditionally performs an operation.
FixedStack(const FixedStack &s)
Copy constructor.
T pop() noexcept
Pop by moving the top of stack.
T & top() noexcept
Return a modifiable reference to stack's top.
FixedStack(FixedStack &&s) noexcept
Move constructor.
void empty() noexcept
Empty the stack.
T & insert(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
const T & base() const noexcept
T & top(const size_t i) noexcept
Return a modifiable reference to item located i positions after top.
T & push(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
Push a copy of data
void clear() noexcept
Empties the container.
T & append(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
bool traverse(Operation &operation) const
FixedStack(size_t d=1024)
The type of element.
const T & top(const size_t i) const noexcept
T & push(T &&data) noexcept(std::is_nothrow_move_assignable_v< T >)
Push and move data
void swap(FixedStack &s) noexcept
Swap in constant time s with this
Simple, scalable and fast dynamic array.
Equality test for containers.
Common methods to the Aleph-w ( ) containers.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_dim_function > > dim(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Singly linked list implementations with head-tail access.
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
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Simple iterator on elements of array.
Generic list of items stored in a container.
Dynamic doubly linked list implementation.
Simple, scalable, contiguous dynamic array.