码迷,mamicode.com
首页 > 编程语言 > 详细

java hashcode的Delphi实现

时间:2014-06-16 09:30:51      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

程序使用java做后台服务,数据处理时使用了java的hashcode,Delphi程序也需要生成这个hashcode,为了一致,所以要在Delphi下实现和Java一样的算法。

下面即Delphi版的hashCode:

bubuko.com,布布扣
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;
bubuko.com,布布扣

 

java hashcode的Delphi实现,布布扣,bubuko.com

java hashcode的Delphi实现

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/GarfieldTom/p/3783503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!