Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
shambase::FixedStack< T, stack_size > Struct Template Reference

Fixed-capacity stack container with compile-time size determination. More...

#include <shambase/include/shambase/FixedStack.hpp>

+ Collaboration diagram for shambase::FixedStack< T, stack_size >:

Public Member Functions

constexpr FixedStack ()
 Default constructor creating an empty stack.
 
constexpr FixedStack (const T &val)
 Constructor creating a stack with one initial element.
 
constexpr bool is_not_empty () const
 Check if the stack contains any elements.
 
constexpr bool empty () const
 Check if the stack is empty.
 
constexpr u32 size () const
 Returns the number of elements in the stack.
 
void push (const T &val)
 Push an element onto the top of the stack.
 
T & top ()
 Access the top element.
 
constexpr const T & top () const
 Access the top element (const version)
 
constexpr void pop ()
 Remove the top element from the stack.
 
pop_ret ()
 Remove and return the top element from the stack.
 

Public Attributes

id_stack [stack_size]
 Storage array for stack elements.
 
u32 stack_cursor
 Cursor pointing to the next available slot (stack_size = empty, 0 = full)
 

Detailed Description

template<class T, u32 stack_size>
struct shambase::FixedStack< T, stack_size >

Fixed-capacity stack container with compile-time size determination.

A high-performance stack implementation that uses a statically allocated array for storage. The stack capacity is determined at compile time, eliminating runtime memory allocation overhead. The implementation uses a cursor-based approach where the cursor points to the next available slot in the stack array.

The stack grows downward in memory (decreasing indices), with the cursor starting at stack_size (empty stack) and decreasing as elements are pushed. This design choice optimizes for common usage patterns in computational algorithms.

Template Parameters
TElement type to store in the stack
stack_sizeMaximum number of elements the stack can hold
Note
The stack array is intentionally not zero-initialized in the default constructor to avoid unnecessary initialization overhead in performance- critical applications.
// Example: Basic stack operations
// Push elements
stack.push(42);
stack.push(17);
stack.push(8);
// Check if stack has elements
while (stack.is_not_empty()) {
u32 value = stack.pop_ret();
// Process value (8, 17, 42 in LIFO order)
}
// Example: Initialize with a value
// Stack contains one element: 100
// Example: Use in tree traversal
while (node_stack.is_not_empty()) {
// Process current node
// Push child nodes for further processing
}
}
std::uint32_t u32
32 bit unsigned integer
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
Fixed-capacity stack container with compile-time size determination.
void push(const T &val)
Push an element onto the top of the stack.
T pop_ret()
Remove and return the top element from the stack.
constexpr bool is_not_empty() const
Check if the stack contains any elements.

Definition at line 88 of file FixedStack.hpp.

Constructor & Destructor Documentation

◆ FixedStack() [1/2]

template<class T , u32 stack_size>
constexpr shambase::FixedStack< T, stack_size >::FixedStack ( )
inlineconstexpr

Default constructor creating an empty stack.

Definition at line 104 of file FixedStack.hpp.

◆ FixedStack() [2/2]

template<class T , u32 stack_size>
constexpr shambase::FixedStack< T, stack_size >::FixedStack ( const T &  val)
inlineconstexpr

Constructor creating a stack with one initial element.

Definition at line 107 of file FixedStack.hpp.

Member Function Documentation

◆ empty()

template<class T , u32 stack_size>
constexpr bool shambase::FixedStack< T, stack_size >::empty ( ) const
inlineconstexpr

Check if the stack is empty.

Definition at line 115 of file FixedStack.hpp.

+ Here is the call graph for this function:

◆ is_not_empty()

template<class T , u32 stack_size>
constexpr bool shambase::FixedStack< T, stack_size >::is_not_empty ( ) const
inlineconstexpr

Check if the stack contains any elements.

Definition at line 112 of file FixedStack.hpp.

+ Here is the call graph for this function:

◆ pop()

template<class T , u32 stack_size>
constexpr void shambase::FixedStack< T, stack_size >::pop ( )
inlineconstexpr

Remove the top element from the stack.

Definition at line 143 of file FixedStack.hpp.

+ Here is the call graph for this function:

◆ pop_ret()

template<class T , u32 stack_size>
T shambase::FixedStack< T, stack_size >::pop_ret ( )
inline

Remove and return the top element from the stack.

Definition at line 153 of file FixedStack.hpp.

+ Here is the call graph for this function:

◆ push()

template<class T , u32 stack_size>
void shambase::FixedStack< T, stack_size >::push ( const T &  val)
inline

Push an element onto the top of the stack.

Definition at line 121 of file FixedStack.hpp.

◆ size()

template<class T , u32 stack_size>
constexpr u32 shambase::FixedStack< T, stack_size >::size ( ) const
inlineconstexpr

Returns the number of elements in the stack.

Definition at line 118 of file FixedStack.hpp.

+ Here is the call graph for this function:

◆ top() [1/2]

template<class T , u32 stack_size>
T & shambase::FixedStack< T, stack_size >::top ( )
inline

Access the top element.

Definition at line 131 of file FixedStack.hpp.

+ Here is the call graph for this function:

◆ top() [2/2]

template<class T , u32 stack_size>
constexpr const T & shambase::FixedStack< T, stack_size >::top ( ) const
inlineconstexpr

Access the top element (const version)

Definition at line 137 of file FixedStack.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ id_stack

template<class T , u32 stack_size>
T shambase::FixedStack< T, stack_size >::id_stack[stack_size]

Storage array for stack elements.

Definition at line 96 of file FixedStack.hpp.

◆ stack_cursor

template<class T , u32 stack_size>
u32 shambase::FixedStack< T, stack_size >::stack_cursor

Cursor pointing to the next available slot (stack_size = empty, 0 = full)

Definition at line 98 of file FixedStack.hpp.


The documentation for this struct was generated from the following file: