unit djenkins32;

{$MODE FPC}
{$MODESWITCH RESULT}

interface

type
  THash32 = UInt32;

function GetJenkins32(Key, KeyEnd: Pointer): THash32; inline; overload;
function GetJenkins32(Key: Pointer; Len: SizeUInt): THash32; inline; overload;

implementation

function _GetJenkins32(Key, KeyEnd: PByte; Temp: THash32): THash32;
begin
  while Key < KeyEnd do begin
    Temp := Temp +   Key^;
    Temp := Temp +   (Temp shl 10);
    Temp := Temp xor (Temp shr 6);
  end;
  Temp := Temp +  (Temp shl 3);
  Temp := Temp or (Temp shr 11);
  Temp := Temp +  (Temp shl 15);
  Exit(Temp);
end;

function GetJenkins32(Key, KeyEnd: Pointer): THash32;
begin
  Exit(_GetJenkins32(Key, KeyEnd, 0));
end;

function GetJenkins32(Key: Pointer; Len: SizeUInt): THash32;
begin
  Exit(_GetJenkins32(Key, Key + Len, 0));
end;

end.
