{$MODE FPC}
{$MODESWITCH DEFAULTPARAMETERS}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}

uses
  dhashbucket,
  dallocator_system in '../dallocator_system.pas',
  dallocator_fixed in '../dallocator_fixed.pas',
  dansistring_manager in '../dansistring_manager.pas',
  ddjb2 in '../ddjb2.pas',
  ddjb2_generic in '../ddjb2_generic.pas',
  dgeneric_hashmap_ptr;

type
THashBucketFromAnsiStringTo = specialize THashBucket<
  AnsiString,
  TAnsiStringManager,
  Pointer,
  TAllocatorSystem>;

TMapFromAnsiStringToPointer = specialize TGenericHashMapToPtr<
  AnsiString,
  TAnsiStringManager,
  Pointer,
  TDjb2Hash,
  TAllocatorFixed512>;

var
  Map: TMapFromAnsiStringToPointer;
  It: TMapFromAnsiStringToPointer.TIteratorAll;

procedure DumpMap;
begin
  It.Init(@Map);
  while It.Next do begin
    Write(It.Item^.Key, #9);
    Writeln(HexStr(PtrUInt(It.Item^.Value), SizeOf(PtrUInt) * 2));
  end;
  It.Done;
end;

begin
  Map.Init;

  Map.Put('a', Pointer($566701));
  Map.Put('b', Pointer($566702));
  Map.Put('c', Pointer($566703));
  Map.Put('d', Pointer($566704));
  Map.Put('e', Pointer($566705));
  Map.Put('f', Pointer($566706));
  Map.Put('xyz', Pointer($123456));
  DumpMap;
  Writeln('    ');

  Map.Remove('b');
  Map.Remove('d');
  DumpMap;
  Writeln('    ');

  Map.Clear;
  Map.Put('foo', Pointer(1));
  Map.Put('bar', Pointer(2));
  Map.Put('lol', Pointer(3));
  Map.Put('baz', Pointer(4));
  Map.Put('kaz', Pointer(5));
  DumpMap;

  Map.Done;
end.
