File indexing completed on 2025-09-15 08:55:03
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011
0012 namespace celeritas
0013 {
0014
0015
0016
0017
0018
0019 template<class T>
0020 class MiniStack
0021 {
0022 public:
0023
0024 using size_type = ::celeritas::size_type;
0025 using value_type = T;
0026
0027
0028 public:
0029
0030 CELER_FUNCTION explicit MiniStack(Span<T> storage)
0031 : data_(storage.data()), capacity_(storage.size())
0032 {
0033 }
0034
0035
0036 CELER_FUNCTION void push(T element)
0037 {
0038 CELER_EXPECT(this->size() < this->capacity());
0039 data_[size_++] = element;
0040 }
0041
0042
0043 CELER_FUNCTION T pop()
0044 {
0045 CELER_EXPECT(!this->empty());
0046 return data_[--size_];
0047 }
0048
0049
0050 CELER_FORCEINLINE_FUNCTION bool empty() const { return size_ == 0; }
0051
0052
0053 CELER_FORCEINLINE_FUNCTION size_type size() const { return size_; }
0054
0055
0056 CELER_FORCEINLINE_FUNCTION size_type capacity() const { return capacity_; }
0057
0058 private:
0059 T* data_;
0060 size_type size_{0};
0061 size_type capacity_;
0062 };
0063
0064
0065 }