zoukankan      html  css  js  c++  java
  • java hashcode的Delphi实现

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

    下面即Delphi版的hashCode:

    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;
  • 相关阅读:
    XML
    DAO
    JDBC
    事物、视图、索引、备份和恢复
    用户
    高级查询2
    高级查询1
    数据库设计
    初识MySQL
    古代和现在的区别Hashtable和HashMap
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/3783503.html
Copyright © 2011-2022 走看看