|
@@ -21,15 +21,19 @@ unit fgl;
|
|
|
|
|
|
interface
|
|
interface
|
|
|
|
|
|
|
|
+ const
|
|
|
|
+ MaxListSize = Maxint div 16;
|
|
|
|
+
|
|
type
|
|
type
|
|
{ TFPList class }
|
|
{ TFPList class }
|
|
generic TGList<TG> = class(TObject)
|
|
generic TGList<TG> = class(TObject)
|
|
type
|
|
type
|
|
- PTGList = ^TPointerList;
|
|
|
|
|
|
+ PTGList = ^TTGList;
|
|
TTGList = array[0..MaxListSize - 1] of TG;
|
|
TTGList = array[0..MaxListSize - 1] of TG;
|
|
TListSortCompare = function (Item1, Item2: TG): Integer;
|
|
TListSortCompare = function (Item1, Item2: TG): Integer;
|
|
TListCallback = procedure(data,arg: TG) of object;
|
|
TListCallback = procedure(data,arg: TG) of object;
|
|
TListStaticCallback = procedure(data,arg: TG);
|
|
TListStaticCallback = procedure(data,arg: TG);
|
|
|
|
+ var
|
|
private
|
|
private
|
|
FList: PTGList;
|
|
FList: PTGList;
|
|
FCount: Integer;
|
|
FCount: Integer;
|
|
@@ -68,6 +72,9 @@ unit fgl;
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
|
|
+ uses
|
|
|
|
+ rtlconsts,sysutils,classes;
|
|
|
|
+
|
|
{****************************************************************************}
|
|
{****************************************************************************}
|
|
{* TGList *}
|
|
{* TGList *}
|
|
{****************************************************************************}
|
|
{****************************************************************************}
|
|
@@ -94,7 +101,7 @@ unit fgl;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- function TGList.Extract(item: Pointer): Pointer;
|
|
|
|
|
|
+ function TGList.Extract(const item: TG): TG;
|
|
var
|
|
var
|
|
i : Integer;
|
|
i : Integer;
|
|
begin
|
|
begin
|
|
@@ -146,7 +153,7 @@ unit fgl;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- function TGList.Add(Item: Pointer): Integer; inline;
|
|
|
|
|
|
+ function TGList.Add(const Item: TG): Integer; inline;
|
|
begin
|
|
begin
|
|
if FCount = FCapacity then
|
|
if FCount = FCapacity then
|
|
Self.Expand;
|
|
Self.Expand;
|
|
@@ -225,7 +232,7 @@ unit fgl;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- function TGList.IndexOf(Item: Pointer): Integer;
|
|
|
|
|
|
+ function TGList.IndexOf(const Item: TG): Integer;
|
|
begin
|
|
begin
|
|
Result := 0;
|
|
Result := 0;
|
|
while(Result < FCount) and (Flist^[Result] <> Item) do Result := Result + 1;
|
|
while(Result < FCount) and (Flist^[Result] <> Item) do Result := Result + 1;
|
|
@@ -271,7 +278,7 @@ unit fgl;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- function TGList.Remove(Item: Pointer): Integer;
|
|
|
|
|
|
+ function TGList.Remove(const Item: TG): Integer;
|
|
begin
|
|
begin
|
|
Result := IndexOf(Item);
|
|
Result := IndexOf(Item);
|
|
If Result <> -1 then
|
|
If Result <> -1 then
|
|
@@ -285,9 +292,11 @@ unit fgl;
|
|
Runner : Longint;
|
|
Runner : Longint;
|
|
begin
|
|
begin
|
|
// Not the fastest; but surely correct
|
|
// Not the fastest; but surely correct
|
|
|
|
+ {
|
|
for Runner := Fcount - 1 downto 0 do
|
|
for Runner := Fcount - 1 downto 0 do
|
|
if Items[Runner] = Nil then
|
|
if Items[Runner] = Nil then
|
|
Self.Delete(Runner);
|
|
Self.Delete(Runner);
|
|
|
|
+ }
|
|
{ The following may be faster in case of large and defragmented lists
|
|
{ The following may be faster in case of large and defragmented lists
|
|
If count=0 then exit;
|
|
If count=0 then exit;
|
|
Runner:=0;I:=0;
|
|
Runner:=0;I:=0;
|