TakeLast SkipLast заменены на более эффективные

This commit is contained in:
Mikhalkovich Stanislav 2019-02-18 10:36:06 +03:00
parent e5f94792b8
commit 0370d6b271
9 changed files with 111 additions and 28 deletions

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "4";
public const string Build = "2";
public const string Revision = "1978";
public const string Revision = "1979";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%MINOR%=4
%REVISION%=1978
%COREVERSION%=2
%REVISION%=1979
%MINOR%=4
%MAJOR%=3

Binary file not shown.

View file

@ -1 +1 @@
!define VERSION '3.4.2.1978'
!define VERSION '3.4.2.1979'

View file

@ -587,6 +587,8 @@ end;
procedure buttonStartClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
if t.ThreadState = System.Threading.ThreadState.Suspended then
begin
DMField.StepFlag := False;
@ -604,6 +606,8 @@ end;
procedure buttonStepClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
DMField.StepFlag := True;
t.Resume;
(GraphABCControl as Control).Focus;

View file

@ -299,12 +299,12 @@ var Sz,Z,Dim: integer;
begin
Sz:=CellSize;
Z:=max(Sz div 12,2);
if Sz>64 then Dim:=10
{if Sz>64 then Dim:=10
else if Sz>56 then Dim:=9
else if Sz>48 then Dim:=8
else if Sz>40 then Dim:=8
else if Sz>34 then Dim:=7
else if Sz>28 then Dim:=6
else} if Sz>28 then Dim:=Round((Sz+20)/8)
else if Sz>22 then Dim:=5
else if Sz>12 then Dim:=4
else Dim:=3;
@ -316,13 +316,21 @@ begin
end;
procedure TRobotField.DrawTag(x,y: integer);
var Sz,sz2: integer;
var sz2: integer;
begin
Sz:=CellSize;
if Sz>80 then sz2:=Sz div 2 - 4
else if Sz>52 then sz2:=Sz div 2 - 3
else if Sz>12 then sz2:=Sz div 2 - 2
else sz2:=Sz div 2 - 1;
var Sz:=CellSize;
var s2 := Sz div 2;
{if Sz>172 then
sz2:=S2 - 6
else} if Sz>132 then
sz2:=S2 - 5
else if Sz>92 then
sz2:=S2 - 4
else if Sz>52 then
sz2:=S2 - 3
else if Sz>12 then
sz2:=S2 - 2
else sz2:=S2 - 1;
if (RobotX=x) and (RobotY=y)
then Brush.Color:=clLightGray
@ -417,10 +425,9 @@ begin
end;
procedure TRobotField.MoveRobot(x,y: integer);
var vx,vy: integer;
begin
vx:=RobotX;
vy:=RobotY;
var vx:=RobotX;
var vy:=RobotY;
RobotX:=x;
RobotY:=y;
DrawCell(vx,vy);
@ -716,6 +723,8 @@ procedure MainWindowClose := SaveIni;
procedure buttonStartClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
if t.ThreadState = System.Threading.ThreadState.Suspended then
begin
robField.StepFlag := False;
@ -733,6 +742,8 @@ end;
procedure buttonStepClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
robField.StepFlag := True;
t.Resume;
(GraphABCControl as Control).Focus;
@ -768,12 +779,11 @@ begin
end;
procedure CorrectWHLT;
var mw,mh: integer;
begin
if (RobField.DimX=0) or (RobField.DimY=0) then
exit;
mw := (GraphABCControl.Width - 30) div RobField.DimX;
mh := (GraphABCControl.Height - 20) div RobField.DimY;
var mw := (GraphABCControl.Width - 30) div RobField.DimX;
var mh := (GraphABCControl.Height - 20) div RobField.DimY;
RobField.CellSize := min(mw,mh);
if RobField.CellSize mod 2 = 1 then
RobField.CellSize := RobField.CellSize - 1;
@ -1106,6 +1116,7 @@ begin
Brush.Color := MainForm.BackColor;
FillRectangle(0,0,1280,1024);
Pen.RoundCap := True;
LoadIni(settings);
MainForm.Invoke(SetWindowBounds, new System.Drawing.Rectangle(settings.Left,settings.Top,settings.Width,settings.Height));

View file

@ -587,6 +587,8 @@ end;
procedure buttonStartClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
if t.ThreadState = System.Threading.ThreadState.Suspended then
begin
DMField.StepFlag := False;
@ -604,6 +606,8 @@ end;
procedure buttonStepClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
DMField.StepFlag := True;
t.Resume;
(GraphABCControl as Control).Focus;

View file

@ -2283,8 +2283,9 @@ const
SEEKEOF_FOR_TEXT_WRITEOPENED = 'Функция SeekEof не может быть вызвана для текстового файла, открытого на запись!!SeekEof function can''t be called for file, opened on writing';
SEEKEOLN_FOR_TEXT_WRITEOPENED = 'Функция SeekEoln не может быть вызвана для текстового файла, открытого на запись!!SeekEoln function can''t be called for file, opened on writing';
BAD_TYPE_IN_RUNTIMESIZEOF = 'Bad Type in RunTimeSizeOf';
PARAMETER_COUNT_MUST_BE_GREATER_0 = 'Параметр count должен быть > 0!!Parameter count must be > 0';
PARAMETER_COUNT_MUST_BE_GREATER_1 = 'Параметр count должен быть > 1!!Parameter count must be > 1';
PARAMETER_MUST_BE_GREATER_EQUAL_0 = 'Параметр должен быть >= 0!!Parameter must be >= 0';
PARAMETER_MUST_BE_GREATER_0 = 'Параметр должен быть > 0!!Parameter must be > 0';
PARAMETER_MUST_BE_GREATER_1 = 'Параметр должен быть > 1!!Parameter must be > 1';
PARAMETER_STEP_MUST_BE_NOT_EQUAL_0 = 'Параметр step не может быть равен 0!!The step parameter must be not equal to 0';
PARAMETER_STEP_MUST_BE_GREATER_0 = 'Параметр step должен быть > 0!!The step parameter must be not greater than 0';
PARAMETER_FROM_OUT_OF_RANGE = 'Параметр from за пределами диапазона!!The from parameter out of bounds';
@ -4105,14 +4106,14 @@ end;
function SeqGen<T>(count: integer; first: T; next: T->T): sequence of T;
begin
if count < 1 then
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_COUNT_MUST_BE_GREATER_0));
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_MUST_BE_GREATER_0));
Result := Iterate(first, next).Take(count);
end;
function SeqGen<T>(count: integer; first, second: T; next: (T,T) ->T): sequence of T;
begin
if count < 1 then
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_COUNT_MUST_BE_GREATER_0));
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_MUST_BE_GREATER_0));
Result := Iterate(first, second, next).Take(count);
end;
@ -4129,7 +4130,7 @@ end;
function ArrGen<T>(count: integer; first: T; next: T->T): array of T;
begin
if count < 1 then
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_COUNT_MUST_BE_GREATER_0));
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_MUST_BE_GREATER_0));
var a := new T[count];
a[0] := first;
for var i := 1 to a.Length - 1 do
@ -4140,7 +4141,7 @@ end;
function ArrGen<T>(count: integer; first, second: T; next: (T,T) ->T): array of T;
begin
if count < 2 then
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_COUNT_MUST_BE_GREATER_1));
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_MUST_BE_GREATER_1));
var a := new T[count];
a[0] := first;
a[1] := second;
@ -8728,14 +8729,73 @@ end;
/// Возвращает последние count элементов последовательности
function TakeLast<T>(Self: sequence of T; count: integer): sequence of T; extensionmethod;
begin
Result := Self.Reverse.Take(count).Reverse;
if count < 0 then
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_MUST_BE_GREATER_EQUAL_0));
if Self is IList<T> then
begin
var lst := Self as IList<T>;
var ind := lst.Count - count;
if ind<0 then ind := 0;
for var i:=ind to lst.Count-1 do
yield lst[i];
exit;
end;
var buf := new List<T>;
var p := 0;
foreach var x in Self do
if buf.Count<count then
buf.Add(x)
else
begin
buf[p] := x;
p := (p+1) mod count;
end;
for var i:=0 to buf.Count do
begin
yield buf[p];
p := (p+1) mod count;
end;
end;
{function TakeLast<T>(Self: sequence of T; count: integer): sequence of T; extensionmethod;
begin
Result := Self.Reverse.Take(count).Reverse;
end;}
/// Возвращает последовательность без последних count элементов
function SkipLast<T>(self: sequence of T; count: integer := 1): sequence of T; extensionmethod;
function SkipLast<T>(Self: sequence of T; count: integer): sequence of T; extensionmethod;
begin
if count < 0 then
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_MUST_BE_GREATER_EQUAL_0));
if Self is IList<T> then
begin
var lst := Self as IList<T>;
for var i:=0 to lst.Count - count - 1 do
yield lst[i];
exit;
end;
var buf := new List<T>(count);
var p := 0;
foreach var x in Self do
if buf.Count<count then
buf.Add(x)
else
begin
yield buf[p];
buf[p] := x;
p := (p+1) mod count;
end;
end;
{function SkipLast<T>(self: sequence of T; count: integer := 1): sequence of T; extensionmethod;
begin
Result := Self.Reverse.Skip(count).Reverse;
end;
end;}
/// Декартово произведение последовательностей
function Cartesian<T, T1>(Self: sequence of T; b: sequence of T1): sequence of (T, T1); extensionmethod;
@ -9302,7 +9362,7 @@ begin
raise new ArgumentException(GetTranslation(PARAMETER_STEP_MUST_BE_NOT_EQUAL_0));
if count < 0 then
raise new ArgumentException(GetTranslation(PARAMETER_COUNT_MUST_BE_GREATER_0));
raise new System.ArgumentOutOfRangeException('count', count, GetTranslation(PARAMETER_MUST_BE_GREATER_EQUAL_0));
if (from < 0) or (from > Len - 1) then
raise new ArgumentException(GetTranslation(PARAMETER_FROM_OUT_OF_RANGE));

View file

@ -723,6 +723,8 @@ procedure MainWindowClose := SaveIni;
procedure buttonStartClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
if t.ThreadState = System.Threading.ThreadState.Suspended then
begin
robField.StepFlag := False;
@ -740,6 +742,8 @@ end;
procedure buttonStepClick(o: Object; e: EventArgs);
begin
if t=nil then
exit;
robField.StepFlag := True;
t.Resume;
(GraphABCControl as Control).Focus;