Nebula
|
#include <idgenerationpool.h>
Provides a system for creating array friendly id numbers with reuse and generations.
Loosely inspired by bitsquid's blog.
It provides a way to recycle Ids using a separate list of generation numbers, New ids are generated incrementally, but once returned, their generation is increased, such that the next time the id is reused, it can be checked for validity against any dangling instances of the previous generations.
Public Member Functions | |
IdGenerationPool () | |
constructor | |
~IdGenerationPool () | |
destructor | |
bool | Allocate (Id32 &id) |
allocate a new id, returns true if a new id was created, and false if an id was reused but with new generation | |
void | Deallocate (Id32 id) |
remove an id | |
bool | IsValid (Id32 id) const |
check if valid | |
Private Attributes | |
Util::Array< generation_t > | generations |
array containing generation value for every index | |
Util::Queue< Id32 > | freeIds |
stores freed indices | |
SizeT | freeIdsSize |
Ids::IdGenerationPool::IdGenerationPool | ( | ) |
constructor
Ids::IdGenerationPool::~IdGenerationPool | ( | ) |
destructor
bool Ids::IdGenerationPool::Allocate | ( | Id32 & | id | ) |
allocate a new id, returns true if a new id was created, and false if an id was reused but with new generation
void Ids::IdGenerationPool::Deallocate | ( | Id32 | id | ) |
remove an id
bool Ids::IdGenerationPool::IsValid | ( | Id32 | id | ) | const |
check if valid
|
private |
stores freed indices
|
private |
|
private |
array containing generation value for every index