...calculate Java hashCode?
Author: Patrik Forsberg
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;
printed from
www.swissdelphicenter.ch
developers knowledge base