Click
Loading...
Searching...
No Matches
stack.hh
1template <typename T, size_t RING_SIZE=256>
2class Stack {
3protected:
4 T ring[RING_SIZE];
5 uint32_t head;
6
7public:
8
9 Stack() {
10 head = 0;
11 }
12
13
17 inline T* extract_burst(unsigned n) {
18 head -= n;
19 T* v = &ring[head];
20 return v;
21 }
22
26 inline void insert_burst(T* batch, unsigned n) {
27 memcpy(&ring[head], batch, n*sizeof(T));
28 head+=n;
29 }
30
34 inline void insert(T e) {
35 ring[head] = e;
36 head+=1;
37 }
38
39 inline unsigned int count() {
40 return head;
41 }
42
43 inline bool has_space() {
44 return head < RING_SIZE;
45 }
46
47 inline bool is_empty() {
48 return head == 0;
49 }
50
51};