MCPcopy Create free account
hub / github.com/diasurgical/devilution / CreateHetTable

Function CreateHetTable

3rdParty/StormLib/src/SBaseFileTable.cpp:1202–1265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1200}
1201
1202TMPQHetTable * CreateHetTable(DWORD dwEntryCount, DWORD dwTotalCount, DWORD dwNameHashBitSize, LPBYTE pbSrcData)
1203{
1204 TMPQHetTable * pHetTable;
1205
1206 pHetTable = STORM_ALLOC(TMPQHetTable, 1);
1207 if(pHetTable != NULL)
1208 {
1209 // Zero the HET table
1210 memset(pHetTable, 0, sizeof(TMPQHetTable));
1211
1212 // Hash sizes less than 0x40 bits are not tested
1213 assert(dwNameHashBitSize == 0x40);
1214
1215 // Calculate masks
1216 pHetTable->AndMask64 = ((dwNameHashBitSize != 0x40) ? ((ULONGLONG)1 << dwNameHashBitSize) : 0) - 1;
1217 pHetTable->OrMask64 = (ULONGLONG)1 << (dwNameHashBitSize - 1);
1218
1219 // If the total count is not entered, use default
1220 if(dwTotalCount == 0)
1221 dwTotalCount = (dwEntryCount * 4) / 3;
1222
1223 // Store the HET table parameters
1224 pHetTable->dwEntryCount = dwEntryCount;
1225 pHetTable->dwTotalCount = dwTotalCount;
1226 pHetTable->dwNameHashBitSize = dwNameHashBitSize;
1227 pHetTable->dwIndexSizeTotal = GetNecessaryBitCount(dwEntryCount);
1228 pHetTable->dwIndexSizeExtra = 0;
1229 pHetTable->dwIndexSize = pHetTable->dwIndexSizeTotal;
1230
1231 // Allocate array of hashes
1232 pHetTable->pNameHashes = STORM_ALLOC(BYTE, dwTotalCount);
1233 if(pHetTable->pNameHashes != NULL)
1234 {
1235 // Make sure the data are initialized
1236 memset(pHetTable->pNameHashes, 0, dwTotalCount);
1237
1238 // Allocate the bit array for file indexes
1239 pHetTable->pBetIndexes = CreateBitArray(dwTotalCount * pHetTable->dwIndexSizeTotal, 0xFF);
1240 if(pHetTable->pBetIndexes != NULL)
1241 {
1242 // Initialize the HET table from the source data (if given)
1243 if(pbSrcData != NULL)
1244 {
1245 // Copy the name hashes
1246 memcpy(pHetTable->pNameHashes, pbSrcData, dwTotalCount);
1247
1248 // Copy the file indexes
1249 memcpy(pHetTable->pBetIndexes->Elements, pbSrcData + dwTotalCount, pHetTable->pBetIndexes->NumberOfBytes);
1250 }
1251
1252 // Return the result HET table
1253 return pHetTable;
1254 }
1255
1256 // Free the name hashes
1257 STORM_FREE(pHetTable->pNameHashes);
1258 }
1259

Callers 2

TranslateHetTableFunction · 0.85
RebuildHetTableFunction · 0.85

Calls 2

GetNecessaryBitCountFunction · 0.85
CreateBitArrayFunction · 0.85

Tested by

no test coverage detected