mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 00:16:15 +02:00
LazUtils: Added unit lazfglhash with generic class TLazFPGHashTable<T>, for usage in fpdebug
git-svn-id: trunk@48844 -
This commit is contained in:
parent
de22645de5
commit
7c10064ae9
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -2785,6 +2785,7 @@ components/lazutils/laz_xmlwrite.pas svneol=native#text/pascal
|
||||
components/lazutils/lazclasses.pas svneol=native#text/pascal
|
||||
components/lazutils/lazconfigstorage.pas svneol=native#text/pascal
|
||||
components/lazutils/lazdbglog.pas svneol=native#text/pascal
|
||||
components/lazutils/lazfglhash.pas svneol=native#text/plain
|
||||
components/lazutils/lazfilecache.pas svneol=native#text/pascal
|
||||
components/lazutils/lazfileutils.inc svneol=native#text/plain
|
||||
components/lazutils/lazfileutils.pas svneol=native#text/pascal
|
||||
|
120
components/lazutils/lazfglhash.pas
Normal file
120
components/lazutils/lazfglhash.pas
Normal file
@ -0,0 +1,120 @@
|
||||
unit lazfglhash;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
contnrs;
|
||||
|
||||
type
|
||||
generic TLazHTGNode<T> = Class(THTCustomNode)
|
||||
Private
|
||||
FData : T;
|
||||
public
|
||||
property Data: T read FData write FData;
|
||||
end;
|
||||
|
||||
{ TLazFPGHashTable }
|
||||
|
||||
generic TLazFPGHashTable<T> = Class(TFPCustomHashTable)
|
||||
Protected
|
||||
type
|
||||
THTGNode = Class(THTCustomNode)
|
||||
Private
|
||||
FData : T;
|
||||
public
|
||||
property Data: T read FData write FData;
|
||||
end;
|
||||
TGIteratorMethod = Procedure(Item: T; const Key: string; var Continue: Boolean) of object;
|
||||
Function CreateNewNode(const aKey : String) : THTCustomNode; override;
|
||||
Procedure AddNode(ANode : THTCustomNode); override;
|
||||
Procedure SetData(const Index: string; AValue: T); virtual;
|
||||
Function GetData(const index: string): T; virtual;
|
||||
{$if not(defined(ver2) or defined(ver3_0))}
|
||||
Function ForEachCall(aMethod: TGIteratorMethod): THTGNode; virtual;
|
||||
{$endif}
|
||||
Public
|
||||
{$if not(defined(ver2) or defined(ver3_0))}
|
||||
Function Iterate(aMethod: TGIteratorMethod): T; virtual;
|
||||
{$endif}
|
||||
Procedure Add(const aKey: string; const aItem: T); virtual;
|
||||
property Items[const index: string]: T read GetData write SetData; default;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{ TFPGHashTable }
|
||||
|
||||
function TLazFPGHashTable.CreateNewNode(const aKey: String): THTCustomNode;
|
||||
begin
|
||||
Result:=THTGNode.CreateWith(aKey);
|
||||
end;
|
||||
|
||||
procedure TLazFPGHashTable.AddNode(ANode: THTCustomNode);
|
||||
begin
|
||||
with THTGNode(ANode) do
|
||||
Add(Key,Data);
|
||||
end;
|
||||
|
||||
procedure TLazFPGHashTable.SetData(const Index: string; AValue: T);
|
||||
begin
|
||||
THTGNode(FindOrCreateNew(index)).Data:=AValue;
|
||||
end;
|
||||
|
||||
function TLazFPGHashTable.GetData(const index: string): T;
|
||||
var
|
||||
node: THTGNode;
|
||||
begin
|
||||
node:=THTGNode(Find(Index));
|
||||
if Assigned(node) then
|
||||
Result:=node.Data;
|
||||
end;
|
||||
|
||||
{$if not(defined(ver2) or defined(ver3_0))}
|
||||
function TLazFPGHashTable.ForEachCall(aMethod: TGIteratorMethod): THTGNode;
|
||||
var
|
||||
i, j: Longword;
|
||||
continue: boolean;
|
||||
begin
|
||||
Result:=nil;
|
||||
continue:=True;
|
||||
if FHashTableSize>0 then
|
||||
for i:=0 to FHashTableSize-1 do
|
||||
if Assigned(Chain(i)) then
|
||||
if chain(i).Count>0 then
|
||||
for j:=0 to Chain(i).Count-1 do
|
||||
begin
|
||||
aMethod(THTGNode(Chain(i)[j]).Data, THTGNode(Chain(i)[j]).Key, continue);
|
||||
if not continue then
|
||||
begin
|
||||
Result:=THTGNode(Chain(i)[j]);
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TLazFPGHashTable.Iterate(aMethod: TGIteratorMethod): T;
|
||||
var
|
||||
N : THTGNode;
|
||||
begin
|
||||
N:=ForEachCall(AMethod);
|
||||
if Assigned(N) then
|
||||
Result:=N.Data
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
procedure TLazFPGHashTable.Add(const aKey: string; const aItem: T);
|
||||
var
|
||||
chn: TFPObjectList;
|
||||
NewNode: THTGNode;
|
||||
begin
|
||||
chn:=FindChainForAdd(akey);
|
||||
NewNode:=THTGNode(CreateNewNode(aKey));
|
||||
NewNode.Data:=aItem;
|
||||
chn.Add(NewNode);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -16,7 +16,7 @@
|
||||
<Description Value="Useful units for Lazarus packages."/>
|
||||
<License Value="Modified LGPL-2"/>
|
||||
<Version Major="1"/>
|
||||
<Files Count="76">
|
||||
<Files Count="77">
|
||||
<Item1>
|
||||
<Filename Value="laz2_dom.pas"/>
|
||||
<UnitName Value="Laz2_DOM"/>
|
||||
@ -316,12 +316,16 @@
|
||||
</Item74>
|
||||
<Item75>
|
||||
<Filename Value="lazutilities.pas"/>
|
||||
<UnitName Value="lazutilities"/>
|
||||
<UnitName Value="LazUtilities"/>
|
||||
</Item75>
|
||||
<Item76>
|
||||
<Filename Value="lazfglhash.pas"/>
|
||||
<UnitName Value="lazfglhash"/>
|
||||
</Item76>
|
||||
<Item77>
|
||||
<Filename Value="lcsvutils.pas"/>
|
||||
<UnitName Value="lcsvutils"/>
|
||||
</Item76>
|
||||
</Item77>
|
||||
</Files>
|
||||
<LazDoc Paths="../../docs/xml/lazutils"/>
|
||||
<i18n>
|
||||
|
@ -16,7 +16,7 @@ uses
|
||||
TTProfile, TTRASTER, TTTables, TTTypes, EasyLazFreeType, LazLoggerBase,
|
||||
LazLoggerDummy, LazClasses, LazFreeTypeFontCollection, LazConfigStorage,
|
||||
UTF8Process, laz2_xpath, DictionaryStringList, LazLoggerProfiling, FPCAdds,
|
||||
LazUtilities, lcsvutils, LazarusPackageIntf;
|
||||
LazUtilities, lazfglhash, lcsvutils, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user