PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
Queue.h
Go to the documentation of this file.
1
9
10#ifndef PBAT_COMMON_QUEUE_H
11#define PBAT_COMMON_QUEUE_H
12
13#include "pbat/HostDevice.h"
14
15namespace pbat {
16namespace common {
17
24template <class T, auto kCapacity = 64>
25class Queue
26{
27 public:
31 PBAT_HOST_DEVICE Queue() : queue{}, begin{0}, end{0}, n{0} {}
37 PBAT_HOST_DEVICE void Push(T value)
38 {
39 queue[end] = value;
40 end = (end + 1) % Capacity();
41 ++n;
42 }
43
48 PBAT_HOST_DEVICE T const& Top() const { return queue[begin]; }
53 PBAT_HOST_DEVICE void Pop()
54 {
55 begin = (begin + 1) % Capacity();
56 --n;
57 }
58
63 PBAT_HOST_DEVICE bool IsFull() const { return n == Capacity(); }
69 PBAT_HOST_DEVICE bool IsEmpty() const { return n == 0; }
75 PBAT_HOST_DEVICE auto Size() const { return n; }
79 PBAT_HOST_DEVICE void Clear() { begin = end = n = 0; }
85 PBAT_HOST_DEVICE constexpr auto Capacity() const { return kCapacity; }
86
87 private:
88 T queue[kCapacity];
89 int begin, end, n;
90};
91
92} // namespace common
93} // namespace pbat
94
95#endif // PBAT_COMMON_QUEUE_H
PBAT_HOST_DEVICE constexpr auto Capacity() const
Get the maximum number of elements in the queue.
Definition Queue.h:85
PBAT_HOST_DEVICE void Clear()
Clear the queue.
Definition Queue.h:79
PBAT_HOST_DEVICE void Pop()
Remove the next element in the queue.
Definition Queue.h:53
PBAT_HOST_DEVICE T const & Top() const
Get the next element in the queue.
Definition Queue.h:48
PBAT_HOST_DEVICE Queue()
Construct empty Queue.
Definition Queue.h:31
PBAT_HOST_DEVICE bool IsFull() const
Check if the queue is full.
Definition Queue.h:63
PBAT_HOST_DEVICE bool IsEmpty() const
Check if the queue is empty.
Definition Queue.h:69
PBAT_HOST_DEVICE auto Size() const
Get the number of elements in the queue.
Definition Queue.h:75
PBAT_HOST_DEVICE void Push(T value)
Add element to the queue.
Definition Queue.h:37
Common functionality.
Definition ArgSort.h:20
The main namespace of the library.
Definition Aliases.h:15