Attempts to search a free hash entry in the hash table being converted. The created hash table must always be of nonzero size, should have no duplicated items and no deleted entries
| 439 | // The created hash table must always be of nonzero size, |
| 440 | // should have no duplicated items and no deleted entries |
| 441 | TMPQHash * FindFreeHashEntry(TMPQHash * pHashTable, DWORD dwHashTableSize, DWORD dwStartIndex) |
| 442 | { |
| 443 | TMPQHash * pHash; |
| 444 | DWORD dwIndex; |
| 445 | |
| 446 | // Set the initial index |
| 447 | dwStartIndex = dwIndex = (dwStartIndex & (dwHashTableSize - 1)); |
| 448 | assert(dwHashTableSize != 0); |
| 449 | |
| 450 | // Search the hash table and return the found entries in the following priority: |
| 451 | for(;;) |
| 452 | { |
| 453 | // We are not expecting to find matching entry in the hash table being built |
| 454 | // We are not expecting to find deleted entry either |
| 455 | pHash = pHashTable + dwIndex; |
| 456 | |
| 457 | // If we found a free entry, we need to stop searching |
| 458 | if(pHash->dwBlockIndex == HASH_ENTRY_FREE) |
| 459 | return pHash; |
| 460 | |
| 461 | // Move to the next hash entry. |
| 462 | // If we reached the starting entry, it's failure. |
| 463 | dwIndex = (dwIndex + 1) & (dwHashTableSize - 1); |
| 464 | if(dwIndex == dwStartIndex) |
| 465 | break; |
| 466 | } |
| 467 | |
| 468 | // We haven't found anything |
| 469 | assert(false); |
| 470 | return NULL; |
| 471 | } |
| 472 | |
| 473 | void DecryptMpkTable(void * pvMpkTable, size_t cbSize) |
| 474 | { |