function StrHash(const SoureStr: string): Cardinal;
const
cLongBits = 32;
cOneEight = 4;
cThreeFourths = 24;
cHighBits = $F0000000;
var
I: Integer;
P: PChar;
Temp: Cardinal;
begin
Result := 0;
P := PChar(SoureStr);
I := Length(SoureStr);
while I > 0 do
begin
Result := (Result shl cOneEight) + Ord(P^);
Temp := Result and cHighBits;
if Temp <> 0 then
Result := (Result xor (Temp shr cThreeFourths)) and (not cHighBits);
Dec(I);
Inc(P);
end;
end;
end.
得到一个字符串的哈希Hash值
最新推荐文章于 2022-04-04 17:19:02 发布
本文介绍了一种用于字符串处理的哈希算法实现细节。该算法通过位操作和字符遍历来计算字符串的哈希值,适用于多种应用场景,如快速查找和去重等。

4067

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



