mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 05:04:06 +02:00
* Implemented IndexOfItem, reversed search again in IndexOf
git-svn-id: trunk@19279 -
This commit is contained in:
parent
05c83ab538
commit
4a8914cbb0
@ -179,6 +179,11 @@ type
|
|||||||
function MoveNext: Boolean;
|
function MoveNext: Boolean;
|
||||||
property Current: Pointer read GetCurrent;
|
property Current: Pointer read GetCurrent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$ifdef VER2_4}
|
||||||
|
type
|
||||||
|
TDirection = (FromBeginning, FromEnd);
|
||||||
|
{$endif}
|
||||||
|
|
||||||
TFPList = class(TObject)
|
TFPList = class(TObject)
|
||||||
private
|
private
|
||||||
@ -200,6 +205,10 @@ type
|
|||||||
procedure SetCount(NewCount: Integer);
|
procedure SetCount(NewCount: Integer);
|
||||||
Procedure RaiseIndexError(Index: Integer);
|
Procedure RaiseIndexError(Index: Integer);
|
||||||
public
|
public
|
||||||
|
{$IFNDEF VER2_4}
|
||||||
|
Type
|
||||||
|
TDirection = (FromBeginning, FromEnd);
|
||||||
|
{$ENDIF}
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
Procedure AddList(AList : TFPList);
|
Procedure AddList(AList : TFPList);
|
||||||
function Add(Item: Pointer): Integer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
|
function Add(Item: Pointer): Integer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
|
||||||
@ -212,6 +221,7 @@ type
|
|||||||
function First: Pointer;
|
function First: Pointer;
|
||||||
function GetEnumerator: TFPListEnumerator;
|
function GetEnumerator: TFPListEnumerator;
|
||||||
function IndexOf(Item: Pointer): Integer;
|
function IndexOf(Item: Pointer): Integer;
|
||||||
|
function IndexOfItem(Item: Pointer; Direction: TDirection): Integer;
|
||||||
procedure Insert(Index: Integer; Item: Pointer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
|
procedure Insert(Index: Integer; Item: Pointer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
|
||||||
function Last: Pointer;
|
function Last: Pointer;
|
||||||
procedure Move(CurIndex, NewIndex: Integer);
|
procedure Move(CurIndex, NewIndex: Integer);
|
||||||
|
@ -197,10 +197,33 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TFPList.IndexOf(Item: Pointer): Integer;
|
function TFPList.IndexOf(Item: Pointer): Integer;
|
||||||
|
|
||||||
|
Var
|
||||||
|
C : Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=Count-1;
|
Result:=0;
|
||||||
while (Result >=0) and (Flist^[Result]<>Item) do
|
C:=Count;
|
||||||
Result:=Result - 1;
|
while (Result<C) and (Flist^[Result]<>Item) do
|
||||||
|
Inc(Result);
|
||||||
|
If Result>=C then
|
||||||
|
Result:=-1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TFPList.IndexOfItem(Item: Pointer; Direction: TDirection): Integer;
|
||||||
|
|
||||||
|
Var
|
||||||
|
C : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if Direction=fromBeginning then
|
||||||
|
Result:=IndexOf(Item)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Result:=Count-1;
|
||||||
|
while (Result >=0) and (Flist^[Result]<>Item) do
|
||||||
|
Result:=Result - 1;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPList.Insert(Index: Integer; Item: Pointer);
|
procedure TFPList.Insert(Index: Integer; Item: Pointer);
|
||||||
|
Loading…
Reference in New Issue
Block a user