得到一个字符串的哈希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.

你可能感兴趣的:(Hash)