This commit is contained in:
Areloch 2017-11-05 22:33:32 -06:00
parent f51ce3084f
commit d666322a1b
23 changed files with 9203 additions and 7477 deletions

View file

@ -45,7 +45,7 @@ SimNameDictionary::~SimNameDictionary()
void SimNameDictionary::insert(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
SimObject* checkForDup = find(obj->objectName);
@ -55,47 +55,47 @@ void SimNameDictionary::insert(SimObject* obj)
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
if(!hashTable)
if (!hashTable)
{
hashTable = new SimObject *[DefaultTableSize];
hashTableSize = DefaultTableSize;
hashEntryCount = 0;
dMemset( hashTable, 0, sizeof( *hashTable ) * DefaultTableSize );
dMemset(hashTable, 0, sizeof(*hashTable) * DefaultTableSize);
}
S32 idx = HashPointer(obj->objectName) % hashTableSize;
obj->nextNameObject = hashTable[idx];
hashTable[idx] = obj;
hashEntryCount++;
// Rehash if necessary.
if( hashEntryCount > hashTableSize )
if (hashEntryCount > hashTableSize)
{
// Allocate new table.
U32 newHashTableSize = hashTableSize * 2 + 1;
SimObject** newHashTable = new SimObject *[ newHashTableSize ];
dMemset( newHashTable, 0, sizeof( newHashTable[ 0 ] ) * newHashTableSize );
SimObject** newHashTable = new SimObject *[newHashTableSize];
dMemset(newHashTable, 0, sizeof(newHashTable[0]) * newHashTableSize);
// Move entries over.
for( U32 i = 0; i < hashTableSize; ++ i )
for( SimObject* object = hashTable[ i ]; object != NULL; )
for (U32 i = 0; i < hashTableSize; ++i)
for (SimObject* object = hashTable[i]; object != NULL; )
{
SimObject* next = object->nextNameObject;
idx = HashPointer( object->objectName ) % newHashTableSize;
object->nextNameObject = newHashTable[ idx ];
newHashTable[ idx ] = object;
idx = HashPointer(object->objectName) % newHashTableSize;
object->nextNameObject = newHashTable[idx];
newHashTable[idx] = object;
object = next;
}
// Switch tables.
delete [] hashTable;
delete[] hashTable;
hashTable = newHashTable;
hashTableSize = newHashTableSize;
}
@ -109,16 +109,16 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
{
#ifndef USE_NEW_SIMDICTIONARY
// NULL is a valid lookup - it will always return NULL
if(!hashTable)
if (!hashTable)
return NULL;
Mutex::lockMutex(mutex);
S32 idx = HashPointer(name) % hashTableSize;
SimObject *walk = hashTable[idx];
while(walk)
while (walk)
{
if(walk->objectName == name)
if (walk->objectName == name)
{
Mutex::unlockMutex(mutex);
return walk;
@ -129,28 +129,28 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
Mutex::unlockMutex(mutex);
return NULL;
#else
Mutex::lockMutex(mutex);
StringDictDef::iterator it = root.find(name);
SimObject* f = (it == root.end() ? NULL : it->second);
Mutex::unlockMutex(mutex);
return f;
Mutex::lockMutex(mutex);
StringDictDef::iterator it = root.find(name);
SimObject* f = (it == root.end() ? NULL : it->second);
Mutex::unlockMutex(mutex);
return f;
#endif
}
void SimNameDictionary::remove(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
while(*walk)
while (*walk)
{
if(*walk == obj)
if (*walk == obj)
{
*walk = obj->nextNameObject;
obj->nextNameObject = (SimObject*)-1;
obj->nextNameObject = nullptr;
hashEntryCount--;
Mutex::unlockMutex(mutex);
@ -164,7 +164,7 @@ void SimNameDictionary::remove(SimObject* obj)
root.erase(name);
#endif
Mutex::unlockMutex(mutex);
}
}
//----------------------------------------------------------------------------
@ -174,8 +174,8 @@ SimManagerNameDictionary::SimManagerNameDictionary()
hashTable = new SimObject *[DefaultTableSize];
hashTableSize = DefaultTableSize;
hashEntryCount = 0;
dMemset( hashTable, 0, sizeof( hashTable[ 0 ] ) * hashTableSize );
dMemset(hashTable, 0, sizeof(hashTable[0]) * hashTableSize);
#endif
mutex = Mutex::createMutex();
}
@ -190,7 +190,7 @@ SimManagerNameDictionary::~SimManagerNameDictionary()
void SimManagerNameDictionary::insert(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
Mutex::lockMutex(mutex);
@ -199,34 +199,34 @@ void SimManagerNameDictionary::insert(SimObject* obj)
obj->nextManagerNameObject = hashTable[idx];
hashTable[idx] = obj;
hashEntryCount++;
// Rehash if necessary.
if( hashEntryCount > hashTableSize )
if (hashEntryCount > hashTableSize)
{
// Allocate new table.
U32 newHashTableSize = hashTableSize * 2 + 1;
SimObject** newHashTable = new SimObject *[ newHashTableSize ];
dMemset( newHashTable, 0, sizeof( newHashTable[ 0 ] ) * newHashTableSize );
SimObject** newHashTable = new SimObject *[newHashTableSize];
dMemset(newHashTable, 0, sizeof(newHashTable[0]) * newHashTableSize);
// Move entries over.
for( U32 i = 0; i < hashTableSize; ++ i )
for( SimObject* object = hashTable[ i ]; object != NULL; )
for (U32 i = 0; i < hashTableSize; ++i)
for (SimObject* object = hashTable[i]; object != NULL; )
{
SimObject* next = object->nextManagerNameObject;
idx = HashPointer( object->objectName ) % newHashTableSize;
object->nextManagerNameObject = newHashTable[ idx ];
newHashTable[ idx ] = object;
idx = HashPointer(object->objectName) % newHashTableSize;
object->nextManagerNameObject = newHashTable[idx];
newHashTable[idx] = object;
object = next;
}
// Switch tables.
delete [] hashTable;
delete[] hashTable;
hashTable = newHashTable;
hashTableSize = newHashTableSize;
}
@ -245,9 +245,9 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
#ifndef USE_NEW_SIMDICTIONARY
S32 idx = HashPointer(name) % hashTableSize;
SimObject *walk = hashTable[idx];
while(walk)
while (walk)
{
if(walk->objectName == name)
if (walk->objectName == name)
{
Mutex::unlockMutex(mutex);
return walk;
@ -267,19 +267,19 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
void SimManagerNameDictionary::remove(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
#ifndef USE_NEW_SIMDICTIONARY
Mutex::lockMutex(mutex);
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
while(*walk)
while (*walk)
{
if(*walk == obj)
if (*walk == obj)
{
*walk = obj->nextManagerNameObject;
obj->nextManagerNameObject = (SimObject*)-1;
obj->nextManagerNameObject = nullptr;
hashEntryCount--;
Mutex::unlockMutex(mutex);
@ -293,7 +293,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
root.erase(name);
#endif
Mutex::unlockMutex(mutex);
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
@ -301,7 +301,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
SimIdDictionary::SimIdDictionary()
{
#ifndef USE_NEW_SIMDICTIONARY
dMemset( table, 0, sizeof( table[ 0 ] ) * DefaultTableSize );
dMemset(table, 0, sizeof(table[0]) * DefaultTableSize);
#endif
mutex = Mutex::createMutex();
}
@ -322,7 +322,7 @@ void SimIdDictionary::insert(SimObject* obj)
#ifndef USE_NEW_SIMDICTIONARY
S32 idx = obj->getId() & TableBitMask;
obj->nextIdObject = table[idx];
AssertFatal( obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!" );
AssertFatal(obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!");
table[idx] = obj;
#else
root[obj->getId()] = obj;
@ -336,9 +336,9 @@ SimObject* SimIdDictionary::find(S32 id)
#ifndef USE_NEW_SIMDICTIONARY
S32 idx = id & TableBitMask;
SimObject *walk = table[idx];
while(walk)
while (walk)
{
if(walk->getId() == U32(id))
if (walk->getId() == U32(id))
{
Mutex::unlockMutex(mutex);
return walk;
@ -364,9 +364,9 @@ void SimIdDictionary::remove(SimObject* obj)
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
SimObject **walk = &table[obj->getId() & TableBitMask];
while(*walk && *walk != obj)
while (*walk && *walk != obj)
walk = &((*walk)->nextIdObject);
if(*walk)
if (*walk)
*walk = obj->nextIdObject;
#else
root.erase(obj->getId());