Registriert seit: 12. Aug 2003
Ort: Soest
4.027 Beiträge
Delphi 10.1 Berlin Enterprise
|
AW: Case Syntax
14. Feb 2017, 15:29
So?
Delphi-Quellcode:
uses
Generics.Collections;
type
TMultiMap<TKey,TValue> = class
private
fHashMap: TDictionary<TKey,TList<TValue>>;
public
constructor Create;
destructor Destroy; override;
procedure Add(const key: TKey; const value: TValue);
end;
constructor TMultiMap<TKey, TValue>.Create;
begin
inherited Create;
fHashMap := TObjectDictionary<TKey,TList<TValue>>.Create([doOwnsValues]);
end;
destructor TMultiMap<TKey, TValue>.Destroy;
begin
fHashMap.Free;
inherited;
end;
procedure TMultiMap<TKey, TValue>.Add(const key: TKey; const value: TValue);
var
list: TList<TValue>;
begin
if not fHashMap.TryGetValue(key, list) then
begin
list := TList<TValue>.Create;
fHashMap.Add(key, list);
end;
list.Add(value);
end;
Geändert von Stevie (14. Feb 2017 um 17:14 Uhr)
|
|
Zitat
|