void TAppDictionary::Add(PTApplication pApplication) { HANDLE hTask = GetCurrentTask(); TAppDictionaryEntry *pFreeEntry = NULL; // no free entry yet // First see if table already. If so, replace entry for (TAppDictionaryEntry * pEntry = Table; pEntry < &Table[NumEntries]; pEntry++) { if (pEntry->hTask == hTask) // already in table? { pEntry->pApplication = pApplication; return; } else // see if entry is free { if (!pFreeEntry && pEntry->hTask == 0) // remember this entry pFreeEntry = pEntry; } } // Not in table. See if we encountered a free entry in table. If // so, use it. Otherwise grow table. if ((pEntry = (pFreeEntry ? pFreeEntry : GrowTable())) != 0) { pEntry->hTask = hTask; pEntry->pApplication = pApplication; return; } }
// unify an array of descriptors describing a parallel array of indirection cells bool GenericUnificationHashtable::UnifyDescs(GenericUnificationDesc *descs, UInt32 descCount, UIntTarget *pIndirCells, UInt32 indirCellCount) { UNREFERENCED_PARAMETER(indirCellCount); ASSERT(descCount < 128 * 1024 * 1024); if (m_tableSize < descCount) { if (!GrowTable(descCount)) return false; } #if defined(GENERIC_UNIFICATION_STATS) m_indirCellCount += indirCellCount; UInt64 startTicks = GetTicks(); #endif UInt32 indirCellIndex = 0; for (UInt32 i = 0; i < descCount; i++) { ASSERT(indirCellIndex <= indirCellCount); ASSERT(descs[i].GetIndirCellCount() <= indirCellCount - indirCellIndex); if (!UnifyDesc(&descs[i], &pIndirCells[indirCellIndex])) return false; indirCellIndex += descs[i].GetIndirCellCount(); } #if defined(GENERIC_UNIFICATION_STATS) UInt64 elapsedTicks = GetTicks() - startTicks; m_elapsedTicks += elapsedTicks; #endif return true; }
void HashTable::Add(HashObject* object) { int hash_ref=object->GetHashRef(); Vector *v=&mp_vector_array[hash_ref%m_table_size]; m_number_elements++; v->Add(object); if(mb_sorted){ v->Sort(1); } //our load factor will be 1.0, if the number of elements in the table is greater than the table capacity, we increase that capacity. if(m_number_elements>m_table_size){ GrowTable(); } }
extern filetab_idx DWRAddFileName( char *name, file_table *tab ) /**************************************************************/ { filetab_idx ftidx; char **names; names = (char **)tab->tab; for( ftidx = 0; ftidx < tab->len; ++ftidx ) { if( strcmp( name, *names ) == 0 ) { DWRFREE( name ); return( ftidx ); } names++; } GrowTable( tab ); tab->tab[ftidx].u.name = name; return( ftidx ); }
// this generic type or method is not a duplicate - enter it into the hash table bool GenericUnificationHashtable::EnterDesc(GenericUnificationDesc *pDesc, UIntTarget *pIndirCells) { if (m_tableSize < m_entryCount) { if (!GrowTable(m_entryCount)) return false; } m_entryCount++; UInt32 hashCode = pDesc->m_hashCode & m_hashMask; Entry *pEntry = new (nothrow) Entry(m_table[hashCode], pDesc, pIndirCells); if (pEntry == nullptr) return false; m_table[hashCode] = pEntry; if (pDesc->m_flags & GUF_GC_STATICS) { UInt32 indirCellIndex = pDesc->GetIndirCellIndex(GUF_GC_STATICS); UInt8 *pGcStaticData = (UInt8 *)pIndirCells[indirCellIndex]; StaticGcDesc *pGcStaticsDesc = (StaticGcDesc *)pIndirCells[indirCellIndex + 1]; if (!GetRuntimeInstance()->AddDynamicGcStatics(pGcStaticData, pGcStaticsDesc)) return false; } if (pDesc->m_flags & GUF_THREAD_STATICS) { UInt32 indirCellIndex = pDesc->GetIndirCellIndex(GUF_THREAD_STATICS); UInt32 tlsIndex = *(UInt32 *)pIndirCells[indirCellIndex]; UInt32 tlsOffset = (UInt32)pIndirCells[indirCellIndex + 1]; StaticGcDesc *pGcStaticsDesc = (StaticGcDesc *)pIndirCells[indirCellIndex + 2]; if (!GetRuntimeInstance()->AddDynamicThreadStaticGcData(tlsIndex, tlsOffset, pGcStaticsDesc)) return false; } return true; }
extern void DWRAddIndex( filetab_idx ftidx, file_table *tab, unsigned where ) /***************************************************************************/ { GrowTable( tab ); DWRInsertIndex( ftidx, tab, where ); }