10#ifndef PBAT_COMMON_STACK_H
11#define PBAT_COMMON_STACK_H
13#include "pbat/HostDevice.h"
24template <
class T, auto kCapacity = 64>
31 PBAT_HOST_DEVICE
Stack() : stack{}, size{0} {}
37 PBAT_HOST_DEVICE
void Push(T value) { stack[size++] = value; }
43 PBAT_HOST_DEVICE T
Pop() {
return stack[--size]; }
49 PBAT_HOST_DEVICE T
const&
Top()
const {
return stack[size - 1]; }
55 PBAT_HOST_DEVICE
auto Size()
const {
return size; }
61 PBAT_HOST_DEVICE
bool IsEmpty()
const {
return size == 0; }
67 PBAT_HOST_DEVICE
bool IsFull()
const {
return size == kCapacity; }
71 PBAT_HOST_DEVICE
void Clear() { size = 0; }
80 PBAT_HOST_DEVICE T&
operator[](
auto i) {
return stack[i]; }
89 PBAT_HOST_DEVICE T
const&
operator[](
auto i)
const {
return stack[i]; }
95 PBAT_HOST_DEVICE T*
begin() {
return stack; }
101 PBAT_HOST_DEVICE T*
end() {
return stack + size; }
PBAT_HOST_DEVICE T const & operator[](auto i) const
Read-only access element at index i.
Definition Stack.h:89
PBAT_HOST_DEVICE Stack()
Construct empty Stack.
Definition Stack.h:31
PBAT_HOST_DEVICE bool IsEmpty() const
Check if the stack is empty.
Definition Stack.h:61
PBAT_HOST_DEVICE T * begin()
Pointer to the beginning of the stack.
Definition Stack.h:95
PBAT_HOST_DEVICE auto Size() const
Get the number of elements in the stack.
Definition Stack.h:55
PBAT_HOST_DEVICE void Clear()
Clear the stack.
Definition Stack.h:71
PBAT_HOST_DEVICE void Push(T value)
Add element to the stack.
Definition Stack.h:37
PBAT_HOST_DEVICE T * end()
Pointer to the end of the stack.
Definition Stack.h:101
PBAT_HOST_DEVICE T const & Top() const
Get the top element of the stack.
Definition Stack.h:49
PBAT_HOST_DEVICE T Pop()
Remove the top element from the stack.
Definition Stack.h:43
PBAT_HOST_DEVICE bool IsFull() const
Check if the stack is full.
Definition Stack.h:67
PBAT_HOST_DEVICE T & operator[](auto i)
Access element at index i.
Definition Stack.h:80
Common functionality.
Definition ArgSort.h:20
The main namespace of the library.
Definition Aliases.h:15