Skip to content

Instantly share code, notes, and snippets.

@cedricpinson
Created March 25, 2019 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedricpinson/822a01effbea18c56607d8e8a2ac61ed to your computer and use it in GitHub Desktop.
Save cedricpinson/822a01effbea18c56607d8e8a2ac61ed to your computer and use it in GitHub Desktop.
Testing Handle List
template <Typename T, int count>
struct HandleList
{
HandleList(void* data)
{
_data = static_cast<T*>(data);
for ( int i = 0 ; i < count; i++ )
_freeSpots[i] = i;
_freeSpotCount = count;
}
T* getDataElement(handle h) {
return _data[h.index];
}
Handle getHandle() {
int index = _freeSpots[_freeSpotCount];
_freeSpotCount--;
// check overflow
return Handle(index);
}
void freeHandle(Handle h) {
_freeSpots[_freeSpotCount++] = h.index;
}
T* _data;
int _freeSpots[count];
int _freeSpotCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment