Created
March 25, 2019 15:53
-
-
Save cedricpinson/822a01effbea18c56607d8e8a2ac61ed to your computer and use it in GitHub Desktop.
Testing Handle List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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