mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2025-06-25 05:40:11 +00:00
Introduces a generic, fixed-size `Bucket` type in place of the inner vector. This does add size generics but I think it's a very good tradeoff considering how performance-sensitive this codepath is.
40 lines
617 B
C++
40 lines
617 B
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <optional>
|
|
|
|
template<class T, size_t N>
|
|
class Bucket {
|
|
std::array<T, N> buf;
|
|
size_t sz;
|
|
public:
|
|
Bucket() {
|
|
sz = 0;
|
|
}
|
|
|
|
void add(const T& item) {
|
|
if (sz < N) {
|
|
buf[sz++] = item;
|
|
}
|
|
}
|
|
|
|
std::optional<T> get(size_t idx) const {
|
|
if (idx < sz) {
|
|
return buf[idx];
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
size_t size() const {
|
|
return sz;
|
|
}
|
|
|
|
bool isFull() const {
|
|
return sz == N;
|
|
}
|
|
|
|
void clear() {
|
|
sz = 0;
|
|
}
|
|
};
|