Celeritas 0.7+972e6cd
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
celeritas::IdStack< T, Extent, S > Class Template Reference

Stack "view" that keeps the top element in a local scalar. More...

#include <IdStack.hh>

Public Types

using value_type = T
 
using size_type = S
 

Public Member Functions

 IdStack (Span< T, Extent > storage)
 Construct with underlying spill storage.
 
void push (T element)
 Push an element onto the top of the stack.
 
void pop ()
 Remove the top element.
 
T top () const
 Get the top element.
 
bool empty () const
 Whether there are any elements in the container.
 
size_type size () const
 Get the number of elements.
 
constexpr size_type capacity () const
 Get the number of elements that can fit in the allocated storage.
 

Static Public Attributes

static constexpr std::size_t spill_extent = Extent
 Capacity (may be dynamic)
 

Detailed Description

template<class T, std::size_t Extent = dynamic_extent, class S = ::celeritas::size_type>
class celeritas::IdStack< T, Extent, S >

Stack "view" that keeps the top element in a local scalar.

Template Parameters
Tvalue type
Eextent for spill (dynamic or fixed)

This particular stack requires OpaqueId as its element type, because the default value must evaluate to "false" and is never a valid stack value. Without this restriction it would need an extra boolean in addition to the top item.

The most recently pushed value is always stored in top_. Older values are spilled into the underlying storage. This increases the effective stack capacity by one: for storage size N, the stack capacity is N + 1. The internal size_ tracks only the number of spilled elements in underlying storage. The logical size reported by size() is therefore size_ + !this->empty().

Example:
Array<int, 3> storage;
IdStack stack(Span{storage});
EXPECT_TRUE(stack.empty());
EXPECT_EQ(0, stack.size());
EXPECT_EQ(4, stack.capacity());
// Push and pop
stack.push(42);
EXPECT_FALSE(stack.empty());
EXPECT_EQ(1, stack.size());
EXPECT_EQ(42, stack.top());
stack.pop();
Fixed-size simple array for storage.
Definition Array.hh:44
Stack "view" that keeps the top element in a local scalar.
Definition IdStack.hh:54
Non-owning device-compatible reference to a contiguous span of data.
Definition Span.hh:86

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