Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::DynListStack< T > Class Template Reference

Dynamic stack of elements of generic type T based on a singly linked list. More...

#include <tpl_dynListStack.H>

Inheritance diagram for Aleph::DynListStack< T >:
[legend]
Collaboration diagram for Aleph::DynListStack< T >:
[legend]

Classes

struct  Iterator
 Iterator for traversing elements of the stack. More...
 

Public Types

using Set_Type = DynListStack
 The container type (self-reference for generic programming).
 
using Item_Type = T
 The type of elements stored in the stack.
 
using Key_Type = T
 Alias for Item_Type, required by EqualToMethod mixin.
 
- Public Types inherited from StlAlephIterator< DynListStack< T > >
using iterator = StlIterator< DynListStack< T > >
 
using const_iterator = StlConstIterator< DynListStack< T > >
 

Public Member Functions

void swap (DynListStack &other) noexcept
 Swap the contents of this stack with another.
 
 DynListStack () noexcept
 Construct an empty stack.
 
 DynListStack (const DynListStack &other)
 Copy constructor.
 
 DynListStack (DynListStack &&other) noexcept
 Move constructor.
 
template<template< typename > class List>
 DynListStack (const List< T > &l)
 Enable special constructors from ah-args-ctor.H (initializer_list, etc.)
 
template<class It >
 DynListStack (It b, It e)
 
 DynListStack (std::initializer_list< T > l)
 
DynListStackoperator= (const DynListStack &rhs)
 Copy assignment operator.
 
DynListStackoperator= (DynListStack &&rhs) noexcept
 Move assignment operator.
 
constexpr size_t size () const noexcept
 Return the number of elements in the stack.
 
bool is_empty () const noexcept
 Check if the stack is empty.
 
Tpush (const T &data)
 Push an item by copy onto the top of the stack.
 
Tpush (T &&data)
 Push an item by move onto the top of the stack.
 
template<typename... Args>
Templace (Args &&... args)
 Construct an item in place at the top of the stack.
 
Tappend (const T &data)
 Alias for push() - required by Special_Ctors macro.
 
Tappend (T &&data)
 
Tput (const T &data)
 Alias for push() - for compatibility with queue-like interfaces.
 
Tput (T &&data)
 
Tinsert (const T &data)
 Alias for push() - for STL-like insert semantics.
 
Tinsert (T &&data)
 
T pop ()
 Remove and return the top item of the stack.
 
T get ()
 Alias for pop() - removes and returns the top item.
 
Ttop ()
 Return a modifiable reference to the top item of the stack.
 
const Ttop () const
 Return a const reference to the top item of the stack.
 
Tpeek ()
 Alias for top() - returns reference to top item.
 
const Tpeek () const
 Alias for top() const - returns const reference to top item.
 
void empty () noexcept
 Remove all elements from the stack.
 
void clear () noexcept
 Alias for empty() - removes all elements.
 
template<class Operation >
bool traverse (Operation &operation)
 Traverse all elements from top to bottom.
 
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())
 
Tsearch (const T &key) noexcept
 Search for an item in the stack using equality comparison.
 
const Tsearch (const T &key) const noexcept
 
bool contains (const T &key) const noexcept
 Check if the stack contains a specific value.
 
bool has (const T &key) const noexcept
 Alias for contains().
 
- Public Member Functions inherited from LocateFunctions< DynListStack< 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< DynListStack< 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< __Tmaps_if (Prop prop, Operation &op) const
 Conditional mapping of the elements of the container.
 
Aleph::DynList< __Tmaps_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.
 
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.
 
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< DynListStack< T > >
bool equal_to (const DynListStack< T > &r) const noexcept
 Test if elements of this are exactly contained in another container.
 
bool operator== (const DynListStack< T > &r) const noexcept
 
bool operator!= (const DynListStack< T > &r) const noexcept
 Negation of equal_to()
 
- Public Member Functions inherited from StlAlephIterator< DynListStack< 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

DynList< Ts
 
size_t num_items = 0
 

Additional Inherited Members

Detailed Description

template<typename T>
class Aleph::DynListStack< T >

Dynamic stack of elements of generic type T based on a singly linked list.

DynListStack<T> models a dynamic LIFO (Last-In-First-Out) stack with O(1) time complexity for push, pop, and top operations. The stack grows and shrinks dynamically as elements are added or removed.

Features

  • O(1) operations: push, pop, top, size, is_empty
  • Unbounded capacity: limited only by available memory
  • Move semantics: efficient transfer of ownership
  • Functional interface: supports traverse, maps, filter, foldl, etc.
  • STL-compatible iteration: supports range-based for loops

Example Usage

stack.push(10);
stack.push(20);
stack.push(30);
while (!stack.is_empty())
std::cout << stack.pop() << " "; // Output: 30 20 10
// Using initializer list
DynListStack<std::string> names = {"Alice", "Bob", "Charlie"};
// Functional operations
auto doubled = stack.maps([](int x) { return x * 2; });
Dynamic stack of elements of generic type T based on a singly linked list.
bool is_empty() const noexcept
Check if the stack is empty.
T pop()
Remove and return the top item of the stack.
T & push(const T &data)
Push an item by copy onto the top of the stack.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Definition ah-dry.H:904

Thread Safety

This class is not thread-safe. External synchronization is required for concurrent access from multiple threads.

Template Parameters
TType of elements stored in the stack. Must be copy-constructible or move-constructible.
See also
DynListQueue For a FIFO queue implementation
ArrayStack For a fixed-capacity array-based stack
FixedStack For a compile-time fixed-size stack
Author
Leandro Rabindranath León

Definition at line 103 of file tpl_dynListStack.H.

Member Typedef Documentation

◆ Item_Type

template<typename T >
using Aleph::DynListStack< T >::Item_Type = T

The type of elements stored in the stack.

Definition at line 119 of file tpl_dynListStack.H.

◆ Key_Type

template<typename T >
using Aleph::DynListStack< T >::Key_Type = T

Alias for Item_Type, required by EqualToMethod mixin.

Definition at line 122 of file tpl_dynListStack.H.

◆ Set_Type

template<typename T >
using Aleph::DynListStack< T >::Set_Type = DynListStack

The container type (self-reference for generic programming).

Definition at line 116 of file tpl_dynListStack.H.

Constructor & Destructor Documentation

◆ DynListStack() [1/6]

template<typename T >
Aleph::DynListStack< T >::DynListStack ( )
inlinenoexcept

Construct an empty stack.

Creates a stack with no elements. The stack is ready to accept elements via push() or emplace().

Time complexity: O(1)

Definition at line 147 of file tpl_dynListStack.H.

◆ DynListStack() [2/6]

template<typename T >
Aleph::DynListStack< T >::DynListStack ( const DynListStack< T > &  other)
inline

Copy constructor.

Constructs a new stack as a copy of other. All elements are copied in LIFO order.

Time complexity: O(n) where n is the size of other.

Parameters
[in]otherThe stack to copy from.
Exceptions
std::bad_allocIf memory allocation fails.
Anyexception thrown by T's copy constructor.

Definition at line 160 of file tpl_dynListStack.H.

◆ DynListStack() [3/6]

template<typename T >
Aleph::DynListStack< T >::DynListStack ( DynListStack< T > &&  other)
inlinenoexcept

Move constructor.

Constructs a new stack by transferring ownership of resources from other. After this operation, other is left in a valid but unspecified state (typically empty).

Time complexity: O(1)

Parameters
[in,out]otherThe stack to move from.

Definition at line 176 of file tpl_dynListStack.H.

References FunctionalMethods< DynListStack< T >, T >::maps(), and Aleph::DynListStack< T >::swap().

◆ DynListStack() [4/6]

template<typename T >
template<template< typename > class List>
Aleph::DynListStack< T >::DynListStack ( const List< T > &  l)
inline

Enable special constructors from ah-args-ctor.H (initializer_list, etc.)

Definition at line 182 of file tpl_dynListStack.H.

◆ DynListStack() [5/6]

template<typename T >
template<class It >
Aleph::DynListStack< T >::DynListStack ( It  b,
It  e 
)
inline

Definition at line 182 of file tpl_dynListStack.H.

◆ DynListStack() [6/6]

template<typename T >
Aleph::DynListStack< T >::DynListStack ( std::initializer_list< T l)
inline

Definition at line 182 of file tpl_dynListStack.H.

Member Function Documentation

◆ append() [1/2]

template<typename T >
Aleph::DynListStack< T >::append ( const T data)
inline

Alias for push() - required by Special_Ctors macro.

Parameters
[in]dataThe item to append.
Returns
Reference to the newly added item.

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 304 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::push().

Referenced by TEST().

◆ append() [2/2]

template<typename T >
T & Aleph::DynListStack< T >::append ( T &&  data)
inline

Definition at line 307 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::push().

◆ clear()

template<typename T >
void Aleph::DynListStack< T >::clear ( )
inlinenoexcept

Alias for empty() - removes all elements.

Provided for compatibility with STL-style interfaces.

Definition at line 410 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::empty().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST_F().

◆ contains()

template<typename T >
bool Aleph::DynListStack< T >::contains ( const T key) const
inlinenoexcept

Check if the stack contains a specific value.

Time complexity: O(n)

Parameters
[in]keyThe value to search for.
Returns
true if key is found in the stack, false otherwise.

Definition at line 483 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::search().

Referenced by Aleph::DynListStack< T >::has(), and TEST().

◆ emplace()

template<typename T >
template<typename... Args>
T & Aleph::DynListStack< T >::emplace ( Args &&...  args)
inline

Construct an item in place at the top of the stack.

Constructs an element directly at the top of the stack using the provided arguments. This avoids the overhead of creating a temporary object and then copying or moving it.

Time complexity: O(1)

Template Parameters
ArgsTypes of the constructor arguments.
Parameters
[in]argsArguments to forward to the constructor of T.
Returns
A modifiable reference to the newly constructed item.
Exceptions
std::bad_allocIf memory allocation fails.
Anyexception thrown by T's constructor.
Note
Internally, this constructs the object and then moves it. For true in-place construction, the underlying container would need to support allocator-aware construction.

Definition at line 295 of file tpl_dynListStack.H.

References FunctionalMethods< DynListStack< T >, T >::maps(), and Aleph::DynListStack< T >::push().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ empty()

template<typename T >
void Aleph::DynListStack< T >::empty ( )
inlinenoexcept

Remove all elements from the stack.

After this call, size() returns 0 and is_empty() returns true.

Time complexity: O(n) where n is the number of elements.

Definition at line 400 of file tpl_dynListStack.H.

References Aleph::DynList< T >::empty(), Aleph::DynListStack< T >::num_items, and Aleph::DynListStack< T >::s.

Referenced by Aleph::DynListStack< T >::clear(), Aleph::Tarjan_Connected_Components< GT, Itor, SA >::init_tarjan(), TEST(), TEST(), TEST(), and TEST().

◆ get()

template<typename T >
T Aleph::DynListStack< T >::get ( )
inline

Alias for pop() - removes and returns the top item.

Returns
A copy of the removed item.
Exceptions
std::underflow_errorIf the stack is empty.

Definition at line 350 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::pop().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST_F().

◆ has()

template<typename T >
bool Aleph::DynListStack< T >::has ( const T key) const
inlinenoexcept

Alias for contains().

Definition at line 489 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::contains().

◆ insert() [1/2]

template<typename T >
Aleph::DynListStack< T >::insert ( const T data)
inline

Alias for push() - for STL-like insert semantics.

Parameters
[in]dataThe item to insert.
Returns
Reference to the newly added item.

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 322 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::push().

Referenced by TEST(), TEST(), and TEST().

◆ insert() [2/2]

template<typename T >
T & Aleph::DynListStack< T >::insert ( T &&  data)
inline

Definition at line 325 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::push().

◆ is_empty()

◆ operator=() [1/2]

template<typename T >
DynListStack & Aleph::DynListStack< T >::operator= ( const DynListStack< T > &  rhs)
inline

Copy assignment operator.

Replaces the contents of this stack with a copy of rhs.

Time complexity: O(n + m) where n is the current size and m is the size of rhs.

Parameters
[in]rhsThe stack to copy from.
Returns
Reference to this stack.
Exceptions
std::bad_allocIf memory allocation fails.
Anyexception thrown by T's copy constructor.

Definition at line 196 of file tpl_dynListStack.H.

References FunctionalMethods< DynListStack< T >, T >::maps(), Aleph::DynListStack< T >::num_items, and Aleph::DynListStack< T >::s.

◆ operator=() [2/2]

template<typename T >
DynListStack & Aleph::DynListStack< T >::operator= ( DynListStack< T > &&  rhs)
inlinenoexcept

Move assignment operator.

Replaces the contents of this stack by transferring ownership from rhs. After this operation, rhs is left in a valid but unspecified state.

Time complexity: O(1) (plus destruction of current elements).

Parameters
[in,out]rhsThe stack to move from.
Returns
Reference to this stack.

Definition at line 218 of file tpl_dynListStack.H.

References FunctionalMethods< DynListStack< T >, T >::maps(), Aleph::DynListStack< T >::num_items, Aleph::DynListStack< T >::s, and Aleph::DynList< T >::swap().

◆ peek() [1/2]

template<typename T >
T & Aleph::DynListStack< T >::peek ( )
inline

Alias for top() - returns reference to top item.

Returns
Reference to the top item.
Exceptions
std::underflow_errorIf the stack is empty.

Definition at line 386 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::top().

Referenced by TEST(), TEST(), and TEST_F().

◆ peek() [2/2]

template<typename T >
const T & Aleph::DynListStack< T >::peek ( ) const
inline

Alias for top() const - returns const reference to top item.

Returns
Const reference to the top item.
Exceptions
std::underflow_errorIf the stack is empty.

Definition at line 392 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::top().

◆ pop()

template<typename T >
T Aleph::DynListStack< T >::pop ( )
inline

Remove and return the top item of the stack.

Removes the most recently pushed item from the stack and returns it.

Time complexity: O(1)

Returns
A copy of the removed item.
Exceptions
std::underflow_errorIf the stack is empty.
Warning
Calling pop() on an empty stack throws an exception. Use is_empty() to check before calling.

Definition at line 339 of file tpl_dynListStack.H.

References FunctionalMethods< DynListStack< T >, T >::maps(), Aleph::DynListStack< T >::num_items, Aleph::DynList< T >::remove_first(), and Aleph::DynListStack< T >::s.

Referenced by demo_comparison(), demo_stack(), Aleph::DynListStack< T >::get(), Aleph::Tarjan_Connected_Components< GT, Itor, SA >::pop_from_stack(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ push() [1/2]

◆ push() [2/2]

template<typename T >
T & Aleph::DynListStack< T >::push ( T &&  data)
inline

Push an item by move onto the top of the stack.

Moves data onto the top of the stack, avoiding a copy.

Time complexity: O(1)

Parameters
[in]dataThe item to be moved and pushed.
Returns
A modifiable reference to the newly pushed item.
Exceptions
std::bad_allocIf memory allocation fails.

Definition at line 269 of file tpl_dynListStack.H.

References Aleph::DynList< T >::insert(), FunctionalMethods< DynListStack< T >, T >::maps(), Aleph::DynListStack< T >::num_items, and Aleph::DynListStack< T >::s.

◆ put() [1/2]

template<typename T >
Aleph::DynListStack< T >::put ( const T data)
inline

Alias for push() - for compatibility with queue-like interfaces.

Parameters
[in]dataThe item to put.
Returns
Reference to the newly added item.

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 313 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::push().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ put() [2/2]

template<typename T >
T & Aleph::DynListStack< T >::put ( T &&  data)
inline

Definition at line 316 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::push().

◆ search() [1/2]

template<typename T >
const T * Aleph::DynListStack< T >::search ( const T key) const
inlinenoexcept

Definition at line 471 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::search().

◆ search() [2/2]

template<typename T >
Aleph::DynListStack< T >::search ( const T key)
inlinenoexcept

Search for an item in the stack using equality comparison.

Performs a linear search from top to bottom looking for an element equal to key.

Time complexity: O(n)

Parameters
[in]keyThe value to search for.
Returns
Pointer to the item if found, nullptr otherwise.
Note
This method is required by the EqualToMethod mixin.
Warning
The returned pointer is invalidated if the element is removed.

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 465 of file tpl_dynListStack.H.

References LocateFunctions< DynListStack< T >, T >::find_ptr().

Referenced by Aleph::DynListStack< T >::contains(), Aleph::DynListStack< T >::search(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ size()

template<typename T >
constexpr size_t Aleph::DynListStack< T >::size ( ) const
inlineconstexprnoexcept

Return the number of elements in the stack.

Time complexity: O(1)

Returns
The number of elements currently in the stack.

Definition at line 231 of file tpl_dynListStack.H.

References Aleph::DynListStack< T >::num_items.

Referenced by demo_stack(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ swap()

template<typename T >
void Aleph::DynListStack< T >::swap ( DynListStack< T > &  other)
inlinenoexcept

Swap the contents of this stack with another.

Exchanges the contents of this stack with those of other in constant time O(1). No elements are copied or moved individually.

Parameters
[in,out]otherThe stack to swap with.
Note
This operation is noexcept and provides the strong exception guarantee (either succeeds completely or has no effect).

Definition at line 134 of file tpl_dynListStack.H.

References FunctionalMethods< DynListStack< T >, T >::maps(), Aleph::DynListStack< T >::num_items, Aleph::DynListStack< T >::s, and Aleph::DynList< T >::swap().

Referenced by Aleph::DynListStack< T >::DynListStack(), TEST(), and TEST_F().

◆ top() [1/2]

template<typename T >
T & Aleph::DynListStack< T >::top ( )
inline

Return a modifiable reference to the top item of the stack.

Provides access to the top element without removing it.

Time complexity: O(1)

Returns
A modifiable reference to the top item.
Exceptions
std::underflow_errorIf the stack is empty.
Warning
The reference is invalidated if the top element is removed.

Definition at line 363 of file tpl_dynListStack.H.

References Aleph::DynList< T >::get_first(), and Aleph::DynListStack< T >::s.

Referenced by demo_stack(), Aleph::DynListStack< T >::peek(), Aleph::DynListStack< T >::peek(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ top() [2/2]

template<typename T >
const T & Aleph::DynListStack< T >::top ( ) const
inline

Return a const reference to the top item of the stack.

Provides read-only access to the top element without removing it.

Time complexity: O(1)

Returns
A const reference to the top item.
Exceptions
std::underflow_errorIf the stack is empty.

Definition at line 377 of file tpl_dynListStack.H.

References Aleph::DynList< T >::get_first(), and Aleph::DynListStack< T >::s.

◆ traverse() [1/4]

◆ traverse() [2/4]

◆ traverse() [3/4]

template<typename T >
template<class Operation >
Aleph::DynListStack< T >::traverse ( Operation operation)
inline

Traverse all elements from top to bottom.

Executes operation on each element in LIFO order (top to bottom). The traversal stops early if operation returns false.

Template Parameters
OperationA callable type with signature bool(T&) or bool(const T&).
Parameters
[in]operationThe operation to perform on each element.
Returns
true if operation returned true for all elements; false if traversal was stopped early.
Note
The operation receives elements in the order they would be popped from the stack.

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 426 of file tpl_dynListStack.H.

References FunctionalMethods< DynListStack< T >, T >::maps(), Aleph::DynListStack< T >::s, and GenericTraverse< Container >::traverse().

Referenced by TEST().

◆ traverse() [4/4]

Member Data Documentation

◆ num_items

◆ s


The documentation for this class was generated from the following files: