unsigned int getHashCode(CString str)
{
if(str.isEmpty())
return 0;
int len = str.GetLength();
unsigned int ihash = 0;
unsigned int g = 0;
for(int i = 0; i < len;++i)
{
byte temp = (byte)(str.GetAt(i));
ihash = (ihash <<4) + temp;
g = (unsigned int)(ihash & 0xf0000000);
if(g != 0)
{
ihash ^= (g>>24);
ihash ^= g;
}
}
return ihash
}
哈希函数学习
最新推荐文章于 2024-07-22 08:00:00 发布
该代码段展示了一个使用CString作为输入,通过位操作计算哈希值的函数。它首先检查字符串是否为空,然后遍历每个字符,进行位移和异或操作来生成哈希。这种方法常用于简单的哈希表或数据校验。
1929

被折叠的 条评论
为什么被折叠?



