Delphi下的字符串Hash函数

来源:互联网 发布:淘宝联盟二合一连接 编辑:程序博客网 时间:2024/05/09 09:54
有点奇怪,我在Google中查找"Delphi 字符串 Hash"居然找不到相关的Hash函数!正当我不知如何是好是,忽然想起开源的JEDI项目,这个大而全的项目虽然我极少使用,但我知道里面什么都有的。一看果然……

  下面是我从JEDI里面提取出来的Hash函数:

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.

0 0
原创粉丝点击