This commit is contained in:
watrabi
2025-10-28 14:05:46 -04:00
parent 977f1ff4b8
commit c93494f795
452 changed files with 47860 additions and 152 deletions
+36
View File
@@ -0,0 +1,36 @@
#pragma once
namespace RBX {
template<class ElementType, int size=8>
struct FixedSizeCircularBuffer {
private:
ElementType data[size];
unsigned int head;
unsigned int pushed;
public:
FixedSizeCircularBuffer() : head(0), pushed(0) {}
void push(const ElementType& newData) {
head = (head + size - 1) % size;
data[head] = newData;
if (pushed < size) { pushed++; }
}
bool find(const ElementType& key, unsigned int* outIndex) {
for (unsigned int i = 0; i < pushed; ++i) {
if (data[(head + i) % size] == key) {
(*outIndex) = i;
return true;
}
}
return false;
}
const ElementType& operator[](const unsigned int& index) const {
return data[(head + index) % size];
}
};
}