|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Stack implemented with simple dynamic array and with bounds verification. More...
#include <tpl_arrayStack.H>
Classes | |
| class | Iterator |
| Iterator on the items of a stack. More... | |
Public Types | |
| using | Item_Type = T |
Public Types inherited from StlAlephIterator< ArrayStack< T > > | |
| using | iterator = StlIterator< ArrayStack< T > > |
| using | const_iterator = StlConstIterator< ArrayStack< T > > |
Public Member Functions | |
| ArrayStack (size_t dim=4) | |
| The type of element. | |
| ArrayStack (const ArrayStack &s) | |
| Copy constructor. | |
| ArrayStack (ArrayStack &&s) noexcept | |
| Move constructor. | |
| template<template< typename > class List> | |
| ArrayStack (const List< T > &l) | |
| template<class It > | |
| ArrayStack (It b, It e) | |
| ArrayStack (std::initializer_list< T > l) | |
| ArrayStack & | operator= (const ArrayStack &s) |
Assign by copy s to this | |
| void | swap (ArrayStack &s) noexcept |
Swap this with s | |
| ArrayStack & | operator= (ArrayStack &&s) noexcept |
Assign by moving s to this | |
| T & | push (const T &data) |
Push into stack a copy of data | |
| T & | push (T &&data) |
Push into stack data | |
| T & | append (const T &data) |
| T & | append (T &&data) |
| T & | insert (const T &data) |
| T & | insert (T &&data) |
| T & | pushn (const size_t &n=1) |
Push n cells into the stack. | |
| T | pop () |
| Extract the last more recently inserted element. | |
| T | pop_ne () noexcept |
| T | popn (size_t n) |
Extract in constant time the n more recently inserted elements of stack. | |
| T & | top () const |
| Return a modifiable reference to youngest element of stack (called the top) | |
| T & | base () noexcept |
| Return a modifiable reference to first element of array. | |
| T & | top (size_t i) const |
Return a modifiable reference to the element located at i positions from top. | |
| T & | get_last () const |
| void | empty () noexcept |
| Empty the stack. | |
| bool | is_empty () const noexcept |
Return true if stack is empty. | |
| size_t | size () const noexcept |
| Return the number of elements stored in the stack. | |
| size_t | capacity () const noexcept |
| Return the internal capacity. | |
| template<class Operation > | |
| bool | traverse (Operation &operation) |
| Traverse all the items of stack from the youngest to oldest and conditionally performs an operation. | |
| template<class Operation > | |
| bool | traverse (Operation &operation) const |
| template<class Operation > | |
| bool | traverse (Operation &&operation=Operation()) const |
| template<class Operation > | |
| bool | traverse (Operation &&operation=Operation()) |
Public Member Functions inherited from LocateFunctions< ArrayStack< T >, T > | |
| auto | get_it () const |
| Return a properly initialized iterator positioned at the first item on the container. | |
| auto | get_it (const size_t pos) const |
Return a properly initialized iterator positioned at the pos item on the container. | |
| auto | get_itor () const |
Alias of get_it(). | |
| T & | nth_ne (const size_t n) noexcept |
| Return the n‑th element without bounds checking. | |
| const T & | nth_ne (const size_t n) const noexcept |
Const overload of nth_ne(size_t). | |
| T & | nth (const size_t n) |
| Return the n-th item of container. | |
| const T & | nth (const size_t n) const |
Const overload of nth(size_t). | |
| T * | find_ptr (Operation &operation) noexcept(operation_is_noexcept< Operation >()) |
| Find a pointer to an item in the container according to a searching criteria. | |
| const T * | find_ptr (Operation &operation) const noexcept(operation_is_noexcept< Operation >()) |
Const overload of find_ptr(Operation&). | |
| const T * | find_ptr (Operation &&operation) const noexcept(operation_is_noexcept< Operation >()) |
Overload of find_ptr(Operation&) const that accepts rvalues. | |
| T * | find_ptr (Operation &&operation) noexcept(operation_is_noexcept< Operation >()) |
Overload of find_ptr(Operation&) that accepts rvalues. | |
| size_t | find_index (Operation &operation) const noexcept(operation_is_noexcept< Operation >()) |
| Find the position of an item in the container according to a searching criteria. | |
| size_t | find_index (Operation &&operation) const noexcept(operation_is_noexcept< Operation >()) |
Overload of find_index(Operation&) that accepts rvalues. | |
| std::tuple< bool, T > | find_item (Operation &operation) noexcept(operation_is_noexcept< Operation >()) |
| Safe sequential searching of an item matching a criteria. | |
| std::tuple< bool, T > | find_item (Operation &operation) const noexcept(operation_is_noexcept< Operation >()) |
| std::tuple< bool, T > | find_item (Operation &&operation) noexcept(operation_is_noexcept< Operation >()) |
| std::tuple< bool, T > | find_item (Operation &&operation) const noexcept(operation_is_noexcept< Operation >()) |
Public Member Functions inherited from FunctionalMethods< ArrayStack< T >, T > | |
| void | emplace (Args &&... args) |
| Appends a new element into the container by constructing it in-place with the given args. | |
| void | emplace_end (Args &&... args) |
| void | emplace_ins (Args &&... args) |
| Insert a new element into the container by constructing it in-place with the given args. | |
| size_t | ninsert (Args ... args) |
| Insert n variadic items. | |
| size_t | nappend (Args ... args) |
| Append n variadic items. | |
| void | for_each (Operation &operation) |
| Traverse all the container and performs an operation on each element. | |
| void | for_each (Operation &operation) const |
Const overload of for_each(Operation&). | |
| void | for_each (Operation &&operation) const |
Overload of for_each(Operation&) const that accepts rvalues. | |
| void | for_each (Operation &&operation) |
Overload of for_each(Operation&) that accepts rvalues. | |
| void | each (Operation &operation) |
Alias of for_each(Operation&). | |
| void | each (Operation &operation) const |
Const alias of for_each(Operation&). | |
| void | each (Operation &&operation) const |
Const alias of for_each(Operation&) that accepts rvalues. | |
| void | each (Operation &&operation) |
Alias of for_each(Operation&) that accepts rvalues. | |
| void | each (size_t pos, const size_t slice, Operation &operation) const |
Traverse the container starting at pos taking one item every slice, performing a mutable operation on each visited element. | |
| void | each (const size_t pos, const size_t slice, Operation &&operation) const |
| void | mutable_for_each (Operation &operation) |
| void | mutable_for_each (Operation &&operation) |
| bool | all (Operation &operation) const |
| Check if all the elements of container satisfy a condition. | |
| bool | all (Operation &&operation) const |
Overload of all(Operation&) that accepts rvalues. | |
| bool | exists (Operation &op) const |
| Test for existence in the container of an element satisfying a criteria. | |
| bool | exists (Operation &&op) const |
Overload of exists(Operation&) that accepts rvalues. | |
| Aleph::DynList< __T > | maps (Operation &op) const |
| Map the elements of the container. | |
| Aleph::DynList< __T > | maps (Operation &&op) const |
Overload of maps(Operation&) that accepts rvalues. | |
| Aleph::DynList< __T > | maps_if (Prop prop, Operation &op) const |
| Conditional mapping of the elements of the container. | |
| Aleph::DynList< __T > | maps_if (Prop prop, Operation &&op) const |
Overload of maps_if(Prop, Operation&) that accepts rvalues. | |
| Aleph::DynList< T > | to_dynlist () const |
| Convert container to DynList. | |
| std::vector< T > | to_vector () const |
| Convert container to std::vector. | |
| __T | foldl (const __T &init, Op &op) const |
| Fold the elements of the container to a specific result. | |
| __T | foldl (const __T &init, Op &&op=Op()) const |
Overload of foldl(const __T&, Op&) that accepts rvalues. | |
| __T | fold_left (const __T &init, Op &op) const |
| Alias for foldl with the same accumulator type. | |
| __T | fold_left (const __T &init, Op &&op=Op()) const |
Overload of fold_left(const __T&, Op&) that accepts rvalues. | |
| T | fold (const T &init, Operation &operation) const |
| Simplified version of foldl() where the folded type is the same type of elements stored in the container. | |
| T | fold (const T &init, Operation &&operation) const |
Overload of fold(const T&, Operation&) that accepts rvalues. | |
| Aleph::DynList< T > | filter (Operation &operation) const |
| Filter the elements of a container according to a matching criteria. | |
| Aleph::DynList< T > | filter (Operation &&operation) const |
Overload of filter(Operation&) that accepts rvalues. | |
| Aleph::DynList< const T * > | ptr_filter (Operation &operation) const |
| Filter the elements of a container according to a matching criteria and return a pointer to the matched items in the container. | |
| Aleph::DynList< const T * > | ptr_filter (Operation &&operation) const |
Overload of ptr_filter(Operation&) that accepts rvalues. | |
| Aleph::DynList< std::tuple< T, size_t > > | pfilter (Operation &operation) const |
| Filter the elements of a container according to a matching criteria and determine its positions respect to the traversal of container. | |
| Aleph::DynList< std::tuple< T, size_t > > | pfilter (Operation &&operation) const |
Overload of pfilter(Operation&) that accepts rvalues. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (Operation &op) const |
| Exclusive partition of container according to a filter criteria. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (Operation &&op) const |
Overload of partition(Operation&) that accepts rvalues. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (size_t n) const |
| Exclusive partition of container in the nth item. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | split_half () const |
| Split the container into two halves by alternating elements. | |
| std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > | tpartition (Operation &op) const |
| Exclusive partition of container according to a filter criteria. | |
| std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > | tpartition (Operation &&op) const |
Overload of tpartition(Operation&) that accepts rvalues. | |
| size_t | length () const noexcept |
| Count the number of elements of a container. | |
| Aleph::DynList< T > | rev () const |
| Return a list with the elements of container in reverse order respect to its traversal order. | |
| Aleph::DynList< T > | take (const size_t n) const |
| Return a list with the first n elements seen in the container during its traversal. | |
| Aleph::DynList< T > | take (size_t i, const size_t j, const size_t step=1) const |
| Return a list with elements seen in the container between i and j position respect to its traversal. | |
| Aleph::DynList< T > | drop (const size_t n) const |
| Drop the first n elements seen in the container during its traversal. | |
| void | mutable_drop (const size_t n) |
| Drop the first n elements seen from container. | |
Public Member Functions inherited from GenericItems< Container, T > | |
| Aleph::DynList< T > | items () const |
| Return a list of all the elements of a container sorted by traversal order. | |
| Aleph::DynList< T > | keys () const |
Public Member Functions inherited from EqualToMethod< ArrayStack< T > > | |
| bool | equal_to (const ArrayStack< T > &r) const noexcept |
Test if elements of this are exactly contained in another container. | |
| bool | operator== (const ArrayStack< T > &r) const noexcept |
| bool | operator!= (const ArrayStack< T > &r) const noexcept |
| Negation of equal_to() | |
Public Member Functions inherited from StlAlephIterator< ArrayStack< T > > | |
| iterator | begin () noexcept |
| Return an STL-compatible iterator to the first element. | |
| const_iterator | begin () const noexcept |
| Return a const iterator to the first element. | |
| iterator | end () noexcept |
| Return an STL-compatible end iterator. | |
| const_iterator | end () const noexcept |
| Return a const end iterator. | |
| const_iterator | cbegin () const noexcept |
| Return a const iterator to the first element. | |
| const_iterator | cend () const noexcept |
| Return a const end iterator. | |
Private Attributes | |
| MemArray< T > | array |
Additional Inherited Members | |
Related Symbols inherited from FunctionalMethods< ArrayStack< T >, T > | |
| each | |
| each | |
| each | |
Stack implemented with simple dynamic array and with bounds verification.
ArrayStack<T> instruments a stack of elements of generic type T. The stack is store into an internal contiguous array which grows and ungrows dynamically according to the number of elements.
ArrayStack<T> is a good trade-off between performance and memory consumption. In general is faster than a stack implemented with linked list, but since the internal array growths in two powers, the waste of memory could reach twice the number of elements.
You could use FixedStack, which other than the internal array does not dynamically grow, it does not still perform bound_min_clock checks.
Definition at line 79 of file tpl_arrayStack.H.
Definition at line 89 of file tpl_arrayStack.H.
|
inline |
The type of element.
Initializes a stack with a capacity of dim
Definition at line 92 of file tpl_arrayStack.H.
|
inline |
Copy constructor.
Definition at line 95 of file tpl_arrayStack.H.
|
inlinenoexcept |
Move constructor.
Definition at line 98 of file tpl_arrayStack.H.
|
inline |
Definition at line 101 of file tpl_arrayStack.H.
Definition at line 101 of file tpl_arrayStack.H.
|
inline |
Definition at line 101 of file tpl_arrayStack.H.
Definition at line 150 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::push().
Definition at line 153 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::push().
|
inlinenoexcept |
Return a modifiable reference to first element of array.
Definition at line 212 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
|
inlinenoexcept |
Return the internal capacity.
Definition at line 245 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
|
inlinenoexcept |
Empty the stack.
Definition at line 236 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by Aleph::BinNodePrefixIterator< Node >::end(), Aleph::BinNodeInfixIterator< Node >::end(), Aleph::BinNodePrefixIterator< Node >::reset_first(), Aleph::BinNodeInfixIterator< Node >::reset_first(), Aleph::BinNodePrefixIterator< Node >::reset_last(), and Aleph::BinNodeInfixIterator< Node >::reset_last().
|
inline |
Definition at line 233 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::top().
Definition at line 156 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::push().
Definition at line 159 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::push().
|
inlinenoexcept |
Return true if stack is empty.
Definition at line 239 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by Aleph::BinNodeInfixIterator< Node >::is_in_first(), Aleph::BinNodeInfixIterator< Node >::is_last(), Aleph::BinNodePrefixIterator< Node >::next_ne(), Aleph::BinNodeInfixIterator< Node >::next_ne(), and TEST().
|
inlinenoexcept |
Assign by moving s to this
Definition at line 121 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array, and Aleph::ArrayStack< T >::swap().
|
inline |
Assign by copy s to this
Definition at line 104 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
|
inline |
Extract the last more recently inserted element.
| underflow_error | if stack is empty |
Definition at line 182 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by fib_st(), fib_stack(), Aleph::BinNodePrefixIterator< Node >::next_ne(), and Aleph::BinNodeInfixIterator< Node >::next_ne().
|
inlinenoexcept |
Definition at line 187 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Extract in constant time the n more recently inserted elements of stack.
| [in] | n | number of elements to pop |
| underflow_error | if n is greater than stack size |
Definition at line 199 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Push into stack a copy of data
| [in] | data | to be pushed by copy |
data | bad_alloc | if there is no enough memory |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 133 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by SimpleStack::SimpleStack(), Aleph::BinNodeInfixIterator< Node >::advance_to_min(), Aleph::ArrayStack< T >::append(), Aleph::ArrayStack< T >::append(), fib_st(), Aleph::ArrayStack< T >::insert(), Aleph::ArrayStack< T >::insert(), and Aleph::BinNodePrefixIterator< Node >::next_ne().
|
inline |
Push into stack data
| [in] | data | to be pushed by moving |
data | bad_alloc | if there is no enough memory |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 144 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Push n cells into the stack.
pushn(n) is functionally equivalent to perform n pushes 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 |
Definition at line 171 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by fib_stack().
|
inlinenoexcept |
Return the number of elements stored in the stack.
Definition at line 242 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by fib_st(), fib_stack(), and TEST().
|
inlinenoexcept |
Swap this with s
Definition at line 115 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by Aleph::ArrayStack< T >::operator=(), Aleph::BinNodeInfixIterator< Node >::swap(), and Aleph::BinNodePrefixIterator< Node >::swap().
|
inline |
Return a modifiable reference to youngest element of stack (called the top)
Definition at line 206 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array.
Referenced by fib_stack(), Aleph::ArrayStack< T >::get_last(), and TEST().
Return a modifiable reference to the element located at i positions from top.
| [in] | i | número of positions |
i positions after top | out_of_range | if i is greater than the number of elements of stack |
Definition at line 226 of file tpl_arrayStack.H.
References ah_out_of_range_error_if, and Aleph::ArrayStack< T >::array.
|
inline |
Definition at line 276 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array, and FunctionalMethods< ArrayStack< T >, T >::maps().
|
inline |
Definition at line 269 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array, and FunctionalMethods< ArrayStack< T >, T >::maps().
|
inline |
Traverse all the items of stack from the youngest to oldest and conditionally performs an operation.
| [in] | operation | to perform on the current element. If it returns true, the the traversal continues to the next item; otherwise the traversal stops |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 255 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array, and FunctionalMethods< ArrayStack< T >, T >::maps().
|
inline |
Definition at line 262 of file tpl_arrayStack.H.
References Aleph::ArrayStack< T >::array, and FunctionalMethods< ArrayStack< T >, T >::maps().
Definition at line 85 of file tpl_arrayStack.H.
Referenced by Aleph::ArrayStack< T >::base(), Aleph::ArrayStack< T >::capacity(), Aleph::ArrayStack< T >::empty(), Aleph::ArrayStack< T >::is_empty(), Aleph::ArrayStack< T >::operator=(), Aleph::ArrayStack< T >::operator=(), Aleph::ArrayStack< T >::pop(), Aleph::ArrayStack< T >::pop_ne(), Aleph::ArrayStack< T >::popn(), Aleph::ArrayStack< T >::push(), Aleph::ArrayStack< T >::push(), Aleph::ArrayStack< T >::pushn(), Aleph::ArrayStack< T >::size(), Aleph::ArrayStack< T >::swap(), Aleph::ArrayStack< T >::top(), Aleph::ArrayStack< T >::top(), Aleph::ArrayStack< T >::traverse(), Aleph::ArrayStack< T >::traverse(), Aleph::ArrayStack< T >::traverse(), and Aleph::ArrayStack< T >::traverse().