參考文章:《Inside MoPaQ》chapter two
適用場合:存在一個龐大的字串數組,給定一個字串,判斷其是否在字串數組中;
主要思想:
代碼實現:
#include unsigned seed = , index1 = , index2 = (index1 = ; index1 < ; index1++ (index2 = index1, i = ; i < ; i++, index2 += unsigned seed = (seed * + ) % temp1 = (seed & ) << seed = (seed * + ) % temp2 = (seed & cryptTable[index2] = (temp1 | unsigned HashString( *lpszString, unsigned unsigned *key = (unsigned * unsigned seed1 = , seed2 = (*key != ch = toupper(*key++ seed1 = cryptTable[(dwHashType << ) + ch] ^ (seed1 + seed2 = ch + seed1 + seed2 + (seed2 << ) + unsigned MPQHashTableInit( **ppHashTable, i = *p = MPQHASHTABLE *_pHashTable = p = malloc(nTableLength * (p == printf( *ppHashTable = _pHashTable = (MPQHASHTABLE * (i = ; i < nTableLength; i++ (_pHashTable + i)->nHashA = - (_pHashTable + i)->nHashB = - (_pHashTable + i)->bExists = MPQHashTableFree( * (pHashTable != pHashTable = unsigned MPQHashTableAdd( *lpszString, * unsigned HASH_OFFSET = , HASH_A = , HASH_B = unsigned nHash = unsigned nHashA = unsigned nHashB = unsigned nHashStart = nHash % unsigned nHashPos = MPQHASHTABLE *_pHashTable = (MPQHASHTABLE * ((_pHashTable + nHashPos)-> nHashPos = (nHashPos + ) % (nHashPos == (_pHashTable + nHashPos)->nHashA = (_pHashTable + nHashPos)->nHashB = (_pHashTable + nHashPos)->bExists = MPQHashTableIsExist( *lpszString, * unsigned HASH_OFFSET = , HASH_A = , HASH_B = unsigned nHash = unsigned nHashA = unsigned nHashB = unsigned nHashStart = nHash % unsigned nHashPos = MPQHASHTABLE *_pHashTable = (MPQHASHTABLE * ((_pHashTable + nHashPos)-> (((_pHashTable + nHashPos)->nHashA == nHashA) && ((_pHashTable + nHashPos)->nHashB == nHashPos = (nHashPos +) % (nHashPos == - }