40 void Free(
const TYPE& elem);
93 this->freeValues.Clear();
94 this->usedValues.Clear();
95 this->setupFunc =
nullptr;
111 for (i = 0; i < this->
size; i++)
125 this->freeValues = rhs.freeValues;
126 this->usedValues = rhs.usedValues;
136#if NEBULA_BOUNDSCHECKS
137 n_assert(this->usedValues.Size() > elem);
139 return this->usedValues[elem];
149 n_assert(!this->freeValues.IsEmpty());
150 TYPE elem = this->freeValues.PopFront();
151 this->usedValues.Append(elem);
152 return this->usedValues.Back();
162 IndexT idx = this->usedValues.FindIndex(elem);
164 this->usedValues.EraseIndex(idx);
165 this->freeValues.Append(elem);
175 this->usedValues.Erase(iter);
176 this->freeValues.Append(&iter);
196 return this->freeValues.Size();
206 return this->usedValues.Size();
216 this->size = newSize;
217 this->usedValues.Clear();
218 this->freeValues.Clear();
219 this->freeValues.Reserve(newSize);
222 for (i = 0; i < this->size; i++)
224 this->freeValues.Append(TYPE());
225 if (this->setupFunc !=
nullptr) this->setupFunc(this->freeValues[i], i);
236 return this->freeValues.IsEmpty();
246 return this->usedValues.IsEmpty();
256 this->usedValues.Clear();
257 this->freeValues.Clear();
258 this->freeValues.Reserve(this->size);
261 for (i = 0; i < this->size; i++)
263 this->freeValues.Append(TYPE());
264 if (this->setupFunc !=
nullptr) this->setupFunc(this->freeValues[i], i);
276 for (i = 0; i < this->usedValues.Size(); i++)
278 this->freeValues.Append(this->usedValues[i]);
280 this->usedValues.Clear();
290 this->setupFunc = func;
300 return this->usedValues;
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
Implements a fixed size pool, from which objects of a specific type can be allocated and freed for re...
Definition fixedpool.h:20
void operator=(const FixedArray< TYPE > &rhs)
assignment operator
Util::Array< TYPE > freeValues
Definition fixedpool.h:71
void Free(const TYPE &elem)
free element allocated from pool
TYPE & operator[](const IndexT elem)
access operator
FixedPool(SizeT s, std::function< void(TYPE &val, IndexT idx)> setupFunc)
constructor with fixed size
std::function< void(TYPE &val, IndexT idx)> setupFunc
Definition fixedpool.h:69
bool IsEmpty() const
returns true if the pool is empty
const Util::Array< TYPE > & GetAllocated()
get allocated values as array
Util::Array< TYPE > usedValues
Definition fixedpool.h:72
FixedPool()
default constructor
TYPE * Iterator
define iterator
Definition fixedpool.h:23
TYPE & Alloc()
allocate an element in the pool
SizeT NumUsed() const
get number of used elements
void Clear()
clear all pool values
SizeT Size() const
get number of elements
void Free(const Iterator iter)
free element using iterator
void SetSetupFunc(const std::function< void(TYPE &val, IndexT idx)> &func)
set optional setup value
void Reset()
resets all used indices without clearing contents
SizeT size
Definition fixedpool.h:70
void Resize(SizeT newSize)
reset pool and resize pool
SizeT NumFree() const
get number of free elements
bool IsFull() const
returns true if no more free values are available
#define n_assert(exp)
Definition debug.h:50
Math::float2 size
Definition histogramcontext.cc:36
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48