几个 GetHashCode 函数

几个 GetHashCode 函数:


DBTables.pas

Delphi/Pascal code
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
   
    function GetHashCode(Str: PChar): Integer;
    var
      Off, Len, Skip, I: Integer;
    begin
      Result := 0;
      Off := 1;
      Len := StrLen(Str);
      if Len < 16 then
        for I := (Len - 1) downto 0 do
        begin
          Result := (Result * 37) + Ord(Str[Off]);
          Inc(Off);
        end
      else
      begin
        { Only sample some characters }
        Skip := Len div 8;
        I := Len - 1;
        while I >= 0 do
        begin
          Result := (Result * 39) + Ord(Str[Off]);
          Dec(I, Skip);
          Inc(Off, Skip);
        end;
      end;
    end;

Graphics.pas

Delphi/Pascal code
 
1
2
3
4
5
6
7
8
9
10
11
12
 
function GetHashCode(const Buffer; Count: Integer): Word; assembler;
asm
        MOV     ECX,EDX
        MOV     EDX,EAX
        XOR     EAX,EAX
@@1:    ROL     AX,5
        XOR     AL,[EDX]
        INC     EDX
        DEC     ECX
        JNE     @@1
end;

SysUtils.pas

Delphi/Pascal code
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
function HashName(Name: PChar): Cardinal;
asm
  PUSH  ESI
  PUSH  EBX
  MOV   ESI, Name
  XOR   EAX, EAX
 
@@loop:
  ROL   EAX, 5
  MOV   BL, [ESI]
  CMP   BL, 0
  JE    @@done
  CMP   BL, 'A'
  JL    @@LowerCased
  CMP   BL, 'Z'
  JG    @@LowerCased
  OR    BL, 20H // make lower case
@@LowerCased:
  XOR   AL, BL
  INC   ESI
  JMP   @@loop
@@done:
  POP   EBX
  POP   ESI
  RET
end;

HTTPParse.pas

Delphi/Pascal code
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
function GetHashCode(Ident: PChar; Length: Integer): Word;
asm
      PUSH ESI
{$IFNDEF PIC}
    PUSH    EBX
    XOR    EBX,EBX
{$ENDIF}
      MOV  ESI, EAX
      XOR  EAX, EAX
      XOR  ECX, ECX
@@1:  MOV   AL,[ESI]
      ROL    CX,5
      XOR    CL,CharValue.Byte[EBX + EAX]
      INC    ESI
      DEC    EDX
    JNE    @@1
      MOV    EAX,ECX
{$IFNDEF PIC}
    POP    EBX
{$ENDIF}
      POP   ESI
end;

转载于:https://www.cnblogs.com/bjxsky/p/4620101.html

你可能感兴趣的:(几个 GetHashCode 函数)