// deprecated
unit dhash;

interface

type
  THash32 = Cardinal;

THashFunc = function (P: Pointer; Len: LongInt): THash32;

// just simple wrapper over function with THashFunc prototype
PHashWrapper = ^THashWrapper;
THashWrapper = object
private
  FName: String;
  FFunc: THashFunc;
public
  constructor Init(const Name: String; Func: THashFunc);
  function GetHash(P: Pointer; Len: Integer): THash32; inline;
  property Name: String read FName;
  property Func: THashFunc read FFunc;
end;

// parametrizable object
PHash = ^THash;
THash = object
private
  FName: String;
public
  constructor Init(const Name: String = '?');
  function GetHash(P: Pointer; Len: Integer): THash32; virtual; abstract;
  property Name: String read FName;
end;

THashSimple = object(THash)
private
  FFunc: THashFunc;
public
  constructor Init(const Name: String; Func: THashFunc);
  function GetHash(P: Pointer; Len: Integer): THash32; virtual;
  property Func: THashFunc read FFunc;
end;

implementation

constructor THashWrapper.Init(const Name: String; Func: THashFunc);
begin
  FName := Name;
  FFunc := Func;
end;

function THashWrapper.GetHash(P: Pointer; Len: Integer): THash32;
begin
  Result := Func(P, Len);
end;

constructor THash.Init;
begin
  FName := Name;
end;

constructor THashSimple.Init(const Name: String; Func: THashFunc);
begin
  inherited Init(Name);
  FFunc := Func;
end;

function THashSimple.GetHash(P: Pointer; Len: Integer): THash32;
begin
  Result := FFunc(P, Len);
end;

end.
