unit dhashmap;

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

interface

type
generic THashMapImplementation<
        TKey,
        TKeyManager, // initialization, deinitialization, copy
        TValue,
        TValueManager, // initialization, deinitialization, copy
        THashValue,
        THashFunc, // .GetHash(const Key: TKey): THashValue
        TAllocator // .GetMem, .FreeMem, .ReallocMem
    > = object
public type
  PKey = TKey;
  PValue = TValue;
private
  FKeyManager: TKeyManager;
  FValueManager: TValueManager;
  FHashFunc: THashFunc;
  FAllocator: TAllocator;
public
  procedure Init(KeyManagerArg, ValueManagerArg, HashFuncArg, AllocatorArg: Pointer);
  procedure Done;

  function Require(HashValue: THashValue; const Key: TKey; out Value: PValue): Boolean;
  //
  //  Returns:
  //
  //    Value=nil: error, out of memory
  //
  //    Value<>nil, Result=True: allocated new object
  //
  //    Value<>nil, Result=False: the object has been already exist
  //

  function Remove(HashValue: THashValue; const Key: TKey): Boolean;
  //
  //  Returns:
  //
  //    Result=True: the value has been removed
  //
  //    Result=Fasle: no such key in the hashmap
  //
end;

implementation

end.
