예제 #1
0
void SimManagerNameDictionary::remove(SimObject* obj)
{
   if(!obj->objectName)
      return;

#ifdef USE_CLASSIC_SIMDICTIONARY
   Mutex::lockMutex(mutex);

   SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
   while(*walk)
   {
      if(*walk == obj)
      {
         *walk = obj->nextManagerNameObject;
			obj->nextManagerNameObject = (SimObject*)-1;
         hashEntryCount--;

         Mutex::unlockMutex(mutex);
         return;
      }
      walk = &((*walk)->nextManagerNameObject);
   }
#else

	const char* name = StringTable->insert(obj->objectName);
	if (root[name])
		root.erase(name);
#endif
   Mutex::unlockMutex(mutex);
}	
예제 #2
0
SimObject* SimManagerNameDictionary::find(StringTableEntry name)
{
   // NULL is a valid lookup - it will always return NULL

   Mutex::lockMutex(mutex);

#ifdef USE_CLASSIC_SIMDICTIONARY
   S32 idx = HashPointer(name) % hashTableSize;
   SimObject *walk = hashTable[idx];
   while(walk)
   {
      if(walk->objectName == name)
      {
         Mutex::unlockMutex(mutex);
         return walk;
      }
      walk = walk->nextManagerNameObject;
   }
   Mutex::unlockMutex(mutex);

   return NULL;
#else
   SimObject* f = root[StringTable->insert(name)];	
   Mutex::unlockMutex(mutex);
   return f;
#endif
}
예제 #3
0
void SimManagerNameDictionary::insert(SimObject* obj)
{
   if(!obj->objectName)
      return;

   Mutex::lockMutex(mutex);
#ifdef USE_CLASSIC_SIMDICTIONARY
   S32 idx = HashPointer(obj->objectName) % hashTableSize;
   obj->nextManagerNameObject = hashTable[idx];
   hashTable[idx] = obj;
   hashEntryCount++;
   
   // Rehash if necessary.

   if( hashEntryCount > hashTableSize )
   {
      // Allocate new table.
      
      U32 newHashTableSize = hashTableSize * 2 + 1;
      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; )
         {
            SimObject* next = object->nextManagerNameObject;

            idx = HashPointer( object->objectName ) % newHashTableSize;
            object->nextManagerNameObject = newHashTable[ idx ];
            newHashTable[ idx ] = object;
            
            object = next;
         }
         
      // Switch tables.
      
      delete [] hashTable;
      hashTable = newHashTable;
      hashTableSize = newHashTableSize;
   }
#else
   root[StringTable->insert(obj->objectName)] = obj;
#endif
   Mutex::unlockMutex(mutex);
}
예제 #4
0
void SimNameDictionary::insert(SimObject* obj)
{
   if(!obj->objectName)
      return;

   SimObject* checkForDup = find(obj->objectName);

   if (checkForDup)
      Con::warnf("Warning! You have a duplicate datablock name of %s. This can cause problems. You should rename one of them.", obj->objectName);

   Mutex::lockMutex(mutex);
#ifdef USE_CLASSIC_SIMDICTIONARY
   if(!hashTable)
   {
      hashTable = new SimObject *[DefaultTableSize];
      hashTableSize = DefaultTableSize;
      hashEntryCount = 0;
      
      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 )
   {
      // Allocate new table.
      
      U32 newHashTableSize = hashTableSize * 2 + 1;
      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; )
         {
            SimObject* next = object->nextNameObject;

            idx = HashPointer( object->objectName ) % newHashTableSize;
            object->nextNameObject = newHashTable[ idx ];
            newHashTable[ idx ] = object;
            
            object = next;
         }
         
      // Switch tables.
      
      delete [] hashTable;
      hashTable = newHashTable;
      hashTableSize = newHashTableSize;
   }
#else
   root[StringTable->insert(obj->objectName)] = obj;
#endif
   Mutex::unlockMutex(mutex);
}
U32 SimFieldDictionary::getHashValue( StringTableEntry slotName )
{
   return HashPointer( slotName ) % HashTableSize;
}