FPC имеет несколько классов, кроме TStringList, которые реализуют хэш-таблицы:
* lcl/dynhasharray.pp - pointer to pointer
* lcl/stringhashlist.pas - string to pointer
* lcl/avglvltree.pas - TPointerToPointerTree
Usage:
Tree:=TPointerToPointerTree.Create;
Tree[SomePointer]:=SomeData;
Value:=Tree[SomePointer];
Но гораздо проще сделать это с помощью fgl:
uses fgl;
type
TValSet = class(specialize TFPGMap<string, Boolean>)
public
function IsMember(const N: string): Boolean;
procedure Include(const N: string);
procedure Exclude(const N: string);
procedure Intersect(const V:TValSet);
end;
function TValSet.IsMember(const N: string): Boolean;
begin
Result := IndexOf(N) >= 0;
end;
procedure TValSet.Include(const N: string);
begin
KeyData[N] := True;
end;
procedure TValSet.Exclude(const N: string);
begin
Remove(N);
end;
procedure TValSet.Intersect(const V:TValSet);
var i:integer;
N:string;
begin
for i:=Self.Count-1 downto 0 do
begin
N:=Keys[i];
if not V.IsMember(N) then Exclude(N);
end;
end;
Free Pascal Справочник v0.05 © 2007-2024 Igor Salnikov aka SunDoctor