Delphi:高效的哈希函數(shù)程序
//begin
// Result := (Result * 131) + PByte(buf)^;
// Inc(PByte(buf));
// Dec(count);
//end;
end;
function DJBHash(buf: Pointer; count: Integer) : Cardinal; assembler;
asm
PUSHEDI
PUSHEBX
XOR EBX, EBX
MOV ECX, EAX
MOV EAX, 5381
@LOOP:
TESTEDX, EDX
JZ @EXIT
MOV EDI, EAX
SHL EDI, 5
ADD EAX, EDI
MOV BL, [ECX]
ADD EAX, EBX
INC ECX
DEC EDX
JMP @LOOP
@EXIT:
POP EBX
POP EDI
//----------------------------
// Pascal:
//
//Result := 5381;
//while count > 0 do
//begin
// Result := ((Result shl 5) + Result) + PByte(buf)^;
// Inc(PByte(buf));
// Dec(count);
//end;
end;本文引用地址:http://www.ex-cimer.com/article/170867.htm
評論