MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / insert

Method insert

Engine/source/console/simDictionary.cpp:46–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void SimNameDictionary::insert(SimObject* obj)
47{
48 if(!obj || !obj->objectName)
49 return;
50
51 SimObject* checkForDup = find(obj->objectName);
52
53 if (checkForDup)
54 Con::warnf("Warning! You have a duplicate datablock name of %s. This can cause problems. You should rename one of them.", obj->objectName);
55
56 Mutex::lockMutex(mutex);
57#ifndef USE_NEW_SIMDICTIONARY
58 if(!hashTable)
59 {
60 hashTable = new SimObject *[DefaultTableSize];
61 hashTableSize = DefaultTableSize;
62 hashEntryCount = 0;
63
64 dMemset( hashTable, 0, sizeof( *hashTable ) * DefaultTableSize );
65 }
66
67 S32 idx = HashPointer(obj->objectName) % hashTableSize;
68 obj->nextNameObject = hashTable[idx];
69 hashTable[idx] = obj;
70 hashEntryCount++;
71
72 // Rehash if necessary.
73
74 if( hashEntryCount > hashTableSize )
75 {
76 // Allocate new table.
77
78 U32 newHashTableSize = hashTableSize * 2 + 1;
79 SimObject** newHashTable = new SimObject *[ newHashTableSize ];
80 dMemset( newHashTable, 0, sizeof( newHashTable[ 0 ] ) * newHashTableSize );
81
82 // Move entries over.
83
84 for( U32 i = 0; i < hashTableSize; ++ i )
85 for( SimObject* object = hashTable[ i ]; object != NULL; )
86 {
87 SimObject* next = object->nextNameObject;
88
89 idx = HashPointer( object->objectName ) % newHashTableSize;
90 object->nextNameObject = newHashTable[ idx ];
91 newHashTable[ idx ] = object;
92
93 object = next;
94 }
95
96 // Switch tables.
97
98 delete [] hashTable;
99 hashTable = newHashTable;
100 hashTableSize = newHashTableSize;
101 }
102#else
103 root[obj->objectName] = obj;

Callers

nothing calls this directly

Calls 5

findFunction · 0.85
warnfFunction · 0.85
HashPointerFunction · 0.85
dMemsetFunction · 0.50
getIdMethod · 0.45

Tested by

no test coverage detected