6#include <unordered_set>
24 this->wrapped_vector.reserve(max_size);
39 auto it = freelist.begin();
40 if (it != freelist.end()) {
42 freelist.erase(
index);
44 wrapped_vector[
index] = object;
47 index = wrapped_vector.size();
53 wrapped_vector.push_back(
object);
68 if (
index >= wrapped_vector.size())
73 auto it = freelist.find(
index);
75 if (it != freelist.end()) {
79 wrapped_vector[
index] = object;
91 size_t index = wrapped_vector.size();
97 freelist.insert(
index);
98 wrapped_vector.push_back({});
110 if (
index < wrapped_vector.size()) {
112 freelist.insert(
index);
128 if (
index >= wrapped_vector.size())
134 if (freelist.find(
index) != freelist.end()) {
140 return &wrapped_vector[
index];
146 if (
index >= wrapped_vector.size())
152 if (freelist.find(
index) != freelist.end()) {
158 return wrapped_vector[
index];
167 return wrapped_vector.size();
176 return wrapped_vector.size() - freelist.size();
180 ar& wrapped_vector& freelist;
191 std::vector<T> wrapped_vector;
192 std::unordered_set<size_t> freelist;
SmartVector is a wrapper for the std::vector class that adds objects either to the end of the wrapped...
Definition: smartvector.hpp:16
size_t numElements() const
Returns the number of elements in the wrapped vector (not including gaps)
Definition: smartvector.hpp:175
bool remove(size_t index)
Attempts to remove the given object at the given index of the wrapped vector.
Definition: smartvector.hpp:108
SmartVector()
Definition: smartvector.hpp:27
size_t pushEmpty()
Adds an empty object to the end of the wrapped vector (by adding the new index to the freelist.
Definition: smartvector.hpp:90
const T get(size_t index) const
Returns the object stored at the given index if it exists, and returns nullptr otherwise.
Definition: smartvector.hpp:126
T get(size_t index)
Definition: smartvector.hpp:144
size_t size() const
Returns the number of elements allocated in the wrapped vector (including gaps)
Definition: smartvector.hpp:166
bool set(T object, size_t index)
Overwrites the object at the specified index with the given object.
Definition: smartvector.hpp:67
size_t push(T object)
Pushes the given object to the end of the wrapped vector if it is currently full, or to an existing e...
Definition: smartvector.hpp:35
SmartVector(size_t max_size)
Creates a SmartVector instance with a maximum wrapped vector size of the given value.
Definition: smartvector.hpp:22
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: smartvector.hpp:179
GLuint index
Definition: glad.h:1846
@ T
Definition: mazegenerator.hpp:44