garages revision + some fixes

This commit is contained in:
Nikolay Korolev
2020-12-06 19:30:51 +03:00
parent a82188ac07
commit fe918d41c2
11 changed files with 255 additions and 176 deletions

View File

@@ -123,13 +123,19 @@ public:
return m_flags[handle>>8].u == (handle & 0xFF) ?
(T*)&m_entries[handle >> 8] : nil;
}
int GetIndex(T *entry){
int i = GetJustIndex(entry);
return m_flags[i].u + (i<<8);
int GetIndex(T* entry) {
int i = GetJustIndex_NoFreeAssert(entry);
return m_flags[i].u + (i << 8);
}
int GetJustIndex(T *entry){
// TODO: the cast is unsafe
return (int)((U*)entry - m_entries);
int GetJustIndex(T* entry) {
int index = GetJustIndex_NoFreeAssert(entry);
assert(!IsFreeSlot(index));
return index;
}
int GetJustIndex_NoFreeAssert(T* entry) {
int index = ((U*)entry - m_entries);
assert((U*)entry == (U*)&m_entries[index]); // cast is unsafe - check required
return index;
}
int GetNoOfUsedSpaces(void) const {
int i;