44#ifndef TPL_ARRAYSTACK_H
45#define TPL_ARRAYSTACK_H
140 return array.put(data);
151 return array.put(std::forward<T>(data));
163 return push(std::forward<T>(data));
175 return push(std::forward<T>(data));
207 return array.get_ne(1);
241 return array.first();
250 return array.first();
264 const size_t sz =
array.size();
266 return array.access(sz - i - 1);
269 const T &
top(
const size_t i)
const
271 const size_t sz =
array.size();
273 return array(sz - i - 1);
305 return array.size() == 0;
317 return array.capacity();
327 template <
class Operation>
329 bool traverse(Operation &operation)
noexcept(
noexcept(
array.traverse(operation)))
331 return array.traverse(operation);
335 template <
class Operation>
337 bool traverse(Operation &operation)
const noexcept(
noexcept(
array.traverse(operation)))
339 return array.traverse(operation);
343 template <
class Operation>
345 bool traverse(Operation &&operation = Operation()) const
348 return array.traverse(operation);
352 template <
class Operation>
356 return array.traverse(operation);
425 <<
"FixedStack capacity overflow";
438 std::unique_ptr<T[]> tmp(
new T[s.
dim]);
439 for (
size_t i = 0; i <
head; ++i)
441 array = tmp.release();
449 std::swap(
array, s.array);
450 std::swap(
head, s.head);
451 std::swap(
dim, s.dim);
482 T &
push(
const T &data)
noexcept(std::is_nothrow_copy_assignable_v<T>)
494 T &
push(
T &&data)
noexcept(std::is_nothrow_move_assignable_v<T>)
502 T &
append(
const T &data)
noexcept(std::is_nothrow_copy_assignable_v<T>)
508 T &
append(
T &&data)
noexcept(std::is_nothrow_move_assignable_v<T>)
510 return push(std::forward<T>(data));
514 T &
insert(
const T &data)
noexcept(std::is_nothrow_copy_assignable_v<T>)
520 T &
insert(
T &&data)
noexcept(std::is_nothrow_move_assignable_v<T>)
522 return push(std::forward<T>(data));
555 const auto count =
static_cast<size_t>(n);
605 T &
top(
const size_t i)
noexcept
611 const T &
top(
const size_t i)
const noexcept
640 [[nodiscard]]
size_t size() const noexcept
652 template <
class Operation>
656 for (
size_t i = 0; i <
head; i++)
657 if (not
static_cast<bool>(operation(
array[i])))
664 template <
class Operation>
669 for (
size_t i = 0; i <
head; i++)
670 if (not
static_cast<bool>(operation(
static_cast<const T &
>(
array[i]))))
676 template <
class Operation>
678 bool traverse(Operation &&operation = Operation()) const
681 return traverse<Operation>(operation);
685 template <
class Operation>
687 bool traverse(Operation &&operation = Operation()) noexcept(
690 return traverse<Operation>(operation);
739template <
typename T,
size_t N>
742 static_assert(
N > 0,
"InlineStack needs a positive capacity");
743 static_assert(std::is_trivially_copyable_v<T>,
"InlineStack holds trivially copyable items only");
757 for (
size_t i = 0; i <
head; ++i)
767 for (
size_t i = 0; i <
head; ++i)
768 array[i] = s.array[i];
781 [[nodiscard]]
static constexpr size_t capacity() noexcept
816 [[nodiscard]]
T &
top() noexcept
823 [[nodiscard]]
const T &
top() const noexcept
833 [[nodiscard]]
T &
top(
const size_t i)
noexcept
840 [[nodiscard]]
const T &
top(
const size_t i)
const noexcept
854 [[nodiscard]]
const T &
base() const noexcept
867 [[nodiscard]]
size_t size() const noexcept
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_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
STL-compatible iterator adapters for Aleph containers.
#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(ArrayStack< T > &s)
Iterator on the modifiable stack s.
Iterator(const ArrayStack< T > &)=delete
A constant stack is iterated through Const_Iterator.
Stack implemented with simple dynamic array and with bounds verification.
const T & get_last() const
void swap(ArrayStack &s) noexcept
Swap this with s
const T & base() const
Return a constant reference to the oldest element (the base).
T & insert(const T &data)
See push(const T & data).
T & push(const T &data)
Push into stack a copy of 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=Operation()) const noexcept(noexcept(array.traverse(operation)))
See traverse(Operation & operation).
size_t size() const noexcept
Return the number of elements stored in the stack.
bool traverse(Operation &operation) const noexcept(noexcept(array.traverse(operation)))
See traverse(Operation & operation).
bool traverse(Operation &operation) noexcept(noexcept(array.traverse(operation)))
Traverse all the items of stack from the youngest to oldest and conditionally performs an operation.
T & pushn(const size_t &n=1)
Push n cells into the stack.
T & append(T &&data)
See push(T && data).
T & append(const T &data)
See push(const T & data).
const T & top(const size_t i) const
T & insert(T &&data)
See push(T && data).
T & top(const size_t i)
Return a modifiable reference to the element located at i positions from top.
T popn(size_t n)
Extract in constant time the n more recently inserted elements of stack.
void clear() noexcept
Empties the container.
T & push(T &&data)
Push into stack data
T pop()
Extract the last more recently inserted element.
bool traverse(Operation &&operation=Operation()) noexcept(noexcept(array.traverse(operation)))
See traverse(Operation & operation).
ArrayStack(ArrayStack &&s) noexcept
Move constructor.
size_t capacity() const noexcept
Return the internal capacity.
T & base()
Return a modifiable reference to the oldest element (the base).
Iterator wrapper for C++ raw arrays.
Read-only view of an Aleph iterator: the iterator of a constant container.
Iterator on the items of a stack.
Iterator(FixedStack< T > &s)
Iterator on the modifiable stack s.
Iterator(const FixedStack< T > &)=delete
A constant stack is iterated through Const_Iterator.
T & base() noexcept
Return the internal array base.
bool traverse(Operation &&operation=Operation()) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
See traverse(Operation & operation).
bool traverse(Operation &&operation=Operation()) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
See traverse(Operation & operation).
FixedStack & operator=(const FixedStack &s)
Assign by copy s to this
T & push(T &&data) noexcept(std::is_nothrow_move_assignable_v< T >)
Push and move data
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 >)
See push(T && data).
T & append(T &&data) noexcept(std::is_nothrow_move_assignable_v< T >)
See push(T && data).
FixedStack(const size_t d=1024)
The type of element.
bool is_empty() const noexcept
Return true if stack is empty.
T popn(const int n) noexcept
Perform in constant time n pops.
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.
T & push(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
Push a copy of data
void empty() noexcept
Empty the stack.
T & insert(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
See push(const T & data).
const T & base() const noexcept
T & top(const size_t i) noexcept
Return a modifiable reference to item located i positions after top.
void clear() noexcept
Empties the container.
T & append(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
See push(const T & data).
const T & top(const size_t i) const noexcept
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all the items of stack from the youngest to oldest and conditionally performs an operation.
void swap(FixedStack &s) noexcept
Swap in constant time s with this
bool traverse(Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
See traverse(Operation & operation).
Stack of fixed capacity whose storage is inside the object.
T Item_Type
The type of element.
const T & base() const noexcept
See base().
size_t size() const noexcept
Return the number of items.
const T & top(const size_t i) const noexcept
See top(const size_t i).
static constexpr size_t capacity() noexcept
Maximum number of items.
T pop() noexcept
Pop the top; the stack must not be empty.
T & push(const T &data) noexcept
Push a copy of data.
T & top() noexcept
Return a modifiable reference to the top; the stack must not be empty.
void clear() noexcept
See empty().
T popn(const size_t n) noexcept
Perform n pops in constant time.
InlineStack() noexcept=default
Construct an empty stack. The storage is not initialized.
bool is_empty() const noexcept
Return true if the stack is empty.
T & base() noexcept
Return a modifiable reference to the bottom; the stack must not be empty.
const T & top() const noexcept
See top().
void empty() noexcept
Empty the stack.
InlineStack & operator=(const InlineStack &s) noexcept
Assign the items in use of s.
void swap(InlineStack &s) noexcept
Exchange the items in use of s and this, in time O(size()).
T & top(const size_t i) noexcept
Return a modifiable reference to the item i positions below the top.
Simple, scalable and fast dynamic array.
Number Theoretic Transform over Z / MOD Z.
Mixin providing equality comparison for sequence 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.
PredicateWith<F, Args...>, and neither the call nor the conversion of its result to bool can throw.
f(args...) is a valid call whose result is usable as a condition.
__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.
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.