mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 23:29:13 +02:00
* synchronized with trunk
git-svn-id: branches/wasm@48440 -
This commit is contained in:
commit
605246ac3c
@ -14,6 +14,11 @@
|
|||||||
|
|
||||||
unit gdeque;
|
unit gdeque;
|
||||||
|
|
||||||
|
{
|
||||||
|
Implements a generic double ended queue.
|
||||||
|
(See: https://en.wikipedia.org/wiki/Double-ended_queue)
|
||||||
|
}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -35,9 +40,13 @@ type
|
|||||||
procedure MoveSimpleData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
procedure MoveSimpleData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
||||||
procedure MoveManagedData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
procedure MoveManagedData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
||||||
procedure MoveData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
procedure MoveData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
||||||
|
procedure ClearSingleDataEntry(Index: SizeUInt); virtual;
|
||||||
|
procedure ClearData; virtual;
|
||||||
|
property Data: TArr read FData;
|
||||||
public
|
public
|
||||||
function Size():SizeUInt;inline;
|
function Size():SizeUInt;inline;
|
||||||
constructor Create();
|
constructor Create();
|
||||||
|
destructor Destroy(); override;
|
||||||
Procedure Clear;
|
Procedure Clear;
|
||||||
procedure PushBack(value:T);inline;
|
procedure PushBack(value:T);inline;
|
||||||
procedure PushFront(value:T);inline;
|
procedure PushFront(value:T);inline;
|
||||||
@ -63,8 +72,15 @@ begin
|
|||||||
FStart:=0;
|
FStart:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
destructor TDeque.Destroy();
|
||||||
|
begin
|
||||||
|
Clear;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDeque.Clear;
|
procedure TDeque.Clear;
|
||||||
begin
|
begin
|
||||||
|
ClearData;
|
||||||
FDataSize:=0;
|
FDataSize:=0;
|
||||||
FStart:=0;
|
FStart:=0;
|
||||||
end;
|
end;
|
||||||
@ -91,6 +107,7 @@ procedure TDeque.PopFront();inline;
|
|||||||
begin
|
begin
|
||||||
if(FDataSize>0) then
|
if(FDataSize>0) then
|
||||||
begin
|
begin
|
||||||
|
ClearSingleDataEntry(FStart);
|
||||||
inc(FStart);
|
inc(FStart);
|
||||||
dec(FDataSize);
|
dec(FDataSize);
|
||||||
if(FStart=FCapacity) then
|
if(FStart=FCapacity) then
|
||||||
@ -101,7 +118,10 @@ end;
|
|||||||
procedure TDeque.PopBack();inline;
|
procedure TDeque.PopBack();inline;
|
||||||
begin
|
begin
|
||||||
if(FDataSize>0) then
|
if(FDataSize>0) then
|
||||||
|
begin
|
||||||
|
ClearSingleDataEntry((FStart+FDataSize-1)mod FCapacity);
|
||||||
dec(FDataSize);
|
dec(FDataSize);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDeque.PushFront(value:T);inline;
|
procedure TDeque.PushFront(value:T);inline;
|
||||||
@ -131,8 +151,7 @@ end;
|
|||||||
procedure TDeque.SetValue(position:SizeUInt; value:T);inline;
|
procedure TDeque.SetValue(position:SizeUInt; value:T);inline;
|
||||||
begin
|
begin
|
||||||
Assert(position < size, 'Deque access out of range');
|
Assert(position < size, 'Deque access out of range');
|
||||||
if IsManagedType(T) then
|
ClearSingleDataEntry((FStart+position)mod FCapacity);
|
||||||
Finalize(FData[(FStart+position)mod FCapacity]);
|
|
||||||
FData[(FStart+position)mod FCapacity]:=value;
|
FData[(FStart+position)mod FCapacity]:=value;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -149,7 +168,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
procedure TDeque.MoveSimpleData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
procedure TDeque.MoveSimpleData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
|
||||||
begin
|
begin
|
||||||
Move(FData[StartIndex], FData[StartIndex+Offset], NrElems*SizeOf(T));
|
Move(FData[StartIndex], FData[StartIndex+Offset], NrElems*SizeOf(T));
|
||||||
@ -182,6 +200,27 @@ begin
|
|||||||
MoveSimpleData(StartIndex, Offset, NrElems);
|
MoveSimpleData(StartIndex, Offset, NrElems);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDeque.ClearSingleDataEntry(Index: SizeUInt);
|
||||||
|
begin
|
||||||
|
if IsManagedType(T) then
|
||||||
|
begin
|
||||||
|
Finalize(FData[Index]);
|
||||||
|
FillChar(FData[Index], SizeOf(T), 0);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
FData[Index] := default(T);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDeque.ClearData;
|
||||||
|
var
|
||||||
|
i: SizeUint;
|
||||||
|
begin
|
||||||
|
if IsManagedType(T) then
|
||||||
|
for i := Low(FData) to High(FData) do
|
||||||
|
Finalize(FData[i]);
|
||||||
|
FillChar(FData[Low(FData)], SizeUInt(Length(FData))*SizeOf(T), 0);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDeque.IncreaseCapacity;
|
procedure TDeque.IncreaseCapacity;
|
||||||
function Min(const A,B: SizeUInt): SizeUInt; inline; //no need to drag in the entire Math unit ;-)
|
function Min(const A,B: SizeUInt): SizeUInt; inline; //no need to drag in the entire Math unit ;-)
|
||||||
begin
|
begin
|
||||||
|
@ -90,13 +90,13 @@ const
|
|||||||
SNoDynLibsSupport = 'Dynamic libraries not supported. Recompile program with dynamic library driver.';
|
SNoDynLibsSupport = 'Dynamic libraries not supported. Recompile program with dynamic library driver.';
|
||||||
SMissingWStringManager = 'Widestring manager not available. Recompile program with appropriate manager.';
|
SMissingWStringManager = 'Widestring manager not available. Recompile program with appropriate manager.';
|
||||||
SSigQuit = 'SIGQUIT signal received.';
|
SSigQuit = 'SIGQUIT signal received.';
|
||||||
SObjectCheckError = 'Object reference is Nil';
|
SObjectCheckError = 'Object reference is Nil or VMT is damaged';
|
||||||
SOSError = 'System error, (OS Code %d):'+LineEnding+'%s';
|
SOSError = 'System error, (OS Code %d):'+LineEnding+'%s';
|
||||||
SOutOfMemory = 'Out of memory';
|
SOutOfMemory = 'Out of memory';
|
||||||
SOverflow = 'Floating point overflow';
|
SOverflow = 'Floating point overflow';
|
||||||
SPrivilege = 'Privileged instruction';
|
SPrivilege = 'Privileged instruction';
|
||||||
SRangeError = 'Range check error';
|
SRangeError = 'Range check error';
|
||||||
SStackOverflow = 'Stack overflow';
|
SStackOverflow = 'Stack overflow or stack misalignment';
|
||||||
SSafecallException = 'Exception in safecall method';
|
SSafecallException = 'Exception in safecall method';
|
||||||
SiconvError = 'iconv error';
|
SiconvError = 'iconv error';
|
||||||
SThreadError = 'Thread error';
|
SThreadError = 'Thread error';
|
||||||
|
@ -72,6 +72,7 @@ var
|
|||||||
n,s: String;
|
n,s: String;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
excl: Boolean; //search
|
excl: Boolean; //search
|
||||||
|
MElement: TPasElement;
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
excl := False;
|
excl := False;
|
||||||
@ -120,7 +121,9 @@ begin
|
|||||||
excl := (ASubindex > 0);
|
excl := (ASubindex > 0);
|
||||||
end;
|
end;
|
||||||
// cut off Package Name
|
// cut off Package Name
|
||||||
AElement:= AElement.GetModule;
|
MElement:= AElement.GetModule;
|
||||||
|
if Assigned(MElement) then
|
||||||
|
AElement:= MElement;
|
||||||
Result := Copy(Result, Length(AElement.Parent.Name) + 2, MaxInt);
|
Result := Copy(Result, Length(AElement.Parent.Name) + 2, MaxInt);
|
||||||
// to skip dots in unit name
|
// to skip dots in unit name
|
||||||
i := Length(AElement.Name);
|
i := Length(AElement.Name);
|
||||||
|
Loading…
Reference in New Issue
Block a user