Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1#ifndef BVH_V2_STACK_H
2#define BVH_V2_STACK_H
3
4#include <vector>
5#include <cassert>
6
7namespace bvh::v2 {
8
9/// Fixed-size stack that can be used for a BVH traversal.
10template <typename T, unsigned Capacity>
11struct SmallStack {
12 static constexpr unsigned capacity = Capacity;
13
15 unsigned size = 0;
16
17 bool is_empty() const { return size == 0; }
18 bool is_full() const { return size >= capacity; }
19
20 void push(const T& t) {
21 assert(!is_full());
22 elems[size++] = t;
23 }
24
25 T pop() {
26 assert(!is_empty());
27 return elems[--size];
28 }
29};
30
31/// Growing stack that can be used for BVH traversal. Its performance may be lower than a small,
32/// fixed-size stack, depending on the architecture.
33template <typename T>
35 std::vector<T> elems;
36
37 bool is_empty() const { return elems.empty(); }
38 void push(const T& t) { elems.push_back(t); }
39
40 T pop() {
41 assert(!is_empty());
42 auto top = std::move(elems.back());
43 elems.pop_back();
44 return top;
45 }
46
47 void clear() {
48 elems.clear();
49 }
50};
51
52} // namespace bvh::v2
53
54#endif
Definition bbox.h:9
Growing stack that can be used for BVH traversal.
Definition stack.h:34
std::vector< T > elems
Definition stack.h:35
bool is_empty() const
Definition stack.h:37
void push(const T &t)
Definition stack.h:38
Fixed-size stack that can be used for a BVH traversal.
Definition stack.h:11
unsigned size
Definition stack.h:15
bool is_full() const
Definition stack.h:18
bool is_empty() const
Definition stack.h:17
static constexpr unsigned capacity
Definition stack.h:12
T elems[capacity]
Definition stack.h:14
void push(const T &t)
Definition stack.h:20