Tips (1541)
function hashCode(val: string): Integer; var i: Integer; res: Extended; x: Integer; function RoundEx(x: Extended): Integer; begin Result := Trunc(x) + Trunc(Frac(x) * 2); end; begin res := 0; for i := 1 to Length(val) do begin res := res + Ord(val[i]) * Power(31, Length(val) - (i - 1) - 1); end; Result := RoundEx(res); end;
Rate this tip: