unit dpjw32;

{$MODE FPC}
{$MODESWITCH RESULT}

interface

type
  THash32 = UInt32;

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

implementation

function _GetPjw32(Key, KeyEnd: PByte; Temp: THash32): THash32;
begin
  while Key < KeyEnd do begin
    Temp := (Temp shl 4) or Key^;
    if (Temp and $F0000000) <> 0 then
      Temp := (Temp xor (Temp shr 24)) and $FFFFFFF;
    Inc(Key);
  end;
  Exit(Temp);
end;

function GetPjw32(Key, KeyEnd: Pointer): THash32;
begin
  Exit(_GetPjw32(Key, KeyEnd, 0));
end;

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

end.
