-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the Stack class used in Parser to its own header so that it can be used by others. The Stack class has a fixed maximum size. This is useful for traversing a tree on GPU, because recursive function does not work well in device code.
- Loading branch information
1 parent
87de52e
commit f1609d2
Showing
5 changed files
with
31 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef AMREX_STACK_H_ | ||
#define AMREX_STACK_H_ | ||
|
||
namespace amrex { | ||
|
||
template <typename T, int N> | ||
struct Stack | ||
{ | ||
public: | ||
constexpr void push (T v) { m_data[m_size++] = v; } | ||
constexpr void pop () { --m_size; } | ||
[[nodiscard]] constexpr bool empty () const { return m_size == 0; } | ||
[[nodiscard]] constexpr int size () const { return m_size; } | ||
[[nodiscard]] constexpr T const& top () const { return m_data[m_size-1]; } | ||
[[nodiscard]] constexpr T & top () { return m_data[m_size-1]; } | ||
[[nodiscard]] constexpr T operator[] (int i) const { return m_data[i]; } | ||
private: | ||
T m_data[N]; | ||
int m_size = 0; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters