16,471
社区成员
发帖
与我相关
我的任务
分享
bool RemoveKey(const KEY& cKey)
{
UINT uBin = HashKey(cKey)%m_uTableSize; //在这里出错
COpcEntry* pEntry = m_ppHashTable[uBin];
COpcEntry* pPrev = NULL;
.......
}
template<class KEY>
inline UINT HashKey(const KEY& cKey)
{
return ((UINT)(void*)(DWORD)cKey) >> 4;
}
//==============================================================================
// FUNCTION: HashKey<LPCTSTR>
// PURPOSE: String hash key generator.
template<>
inline UINT HashKey<LPCTSTR> (const LPCTSTR& tsKey)
{
LPCTSTR key = tsKey;
if (key == NULL) return -1;
UINT nHash = 0;
while (*key)
nHash = (nHash<<5) + nHash + *key++;
return nHash;
}
//==============================================================================
// FUNCTION: HashKey<COpcString>
// PURPOSE: String object hash key generator.
template<>
inline UINT HashKey<COpcString> (const COpcString& cKey)
{
LPCTSTR key = cKey;
if (key == NULL) return -1;
UINT nHash = 0;
while (*key)
nHash = (nHash<<5) + nHash + *key++;
return nHash;
}