Nebula
Loading...
Searching...
No Matches
Ids::IdGenerationPool Class Reference

#include <idgenerationpool.h>

Detailed Description

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_tgenerations
 array containing generation value for every index
 
Util::Queue< Id32freeIds
 stores freed indices
 
SizeT freeIdsSize
 

Constructor & Destructor Documentation

◆ IdGenerationPool()

Ids::IdGenerationPool::IdGenerationPool ( )

constructor

◆ ~IdGenerationPool()

Ids::IdGenerationPool::~IdGenerationPool ( )

destructor

Member Function Documentation

◆ Allocate()

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

◆ Deallocate()

void Ids::IdGenerationPool::Deallocate ( Id32 id)

remove an id

◆ IsValid()

bool Ids::IdGenerationPool::IsValid ( Id32 id) const

check if valid

Member Data Documentation

◆ freeIds

Util::Queue<Id32> Ids::IdGenerationPool::freeIds
private

stores freed indices

◆ freeIdsSize

SizeT Ids::IdGenerationPool::freeIdsSize
private

◆ generations

Util::Array<generation_t> Ids::IdGenerationPool::generations
private

array containing generation value for every index


The documentation for this class was generated from the following files: