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 Major = "3";
public const string Minor = "4"; public const string Minor = "4";
public const string Build = "2"; public const string Build = "2";
public const string Revision = "1978"; public const string Revision = "1979";
public const string MainVersion = Major + "." + Minor; public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%MINOR%=4
%REVISION%=1978
%COREVERSION%=2 %COREVERSION%=2
%REVISION%=1979
%MINOR%=4
%MAJOR%=3 %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); procedure buttonStartClick(o: Object; e: EventArgs);
begin begin
if t=nil then
exit;
if t.ThreadState = System.Threading.ThreadState.Suspended then if t.ThreadState = System.Threading.ThreadState.Suspended then
begin begin
DMField.StepFlag := False; DMField.StepFlag := False;
@ -604,6 +606,8 @@ end;
procedure buttonStepClick(o: Object; e: EventArgs); procedure buttonStepClick(o: Object; e: EventArgs);
begin begin
if t=nil then
exit;
DMField.StepFlag := True; DMField.StepFlag := True;
t.Resume; t.Resume;
(GraphABCControl as Control).Focus; (GraphABCControl as Control).Focus;

View file

@ -299,12 +299,12 @@ var Sz,Z,Dim: integer;
begin begin
Sz:=CellSize; Sz:=CellSize;
Z:=max(Sz div 12,2); 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>56 then Dim:=9
else if Sz>48 then Dim:=8 else if Sz>48 then Dim:=8
else if Sz>40 then Dim:=8 else if Sz>40 then Dim:=8
else if Sz>34 then Dim:=7 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>22 then Dim:=5
else if Sz>12 then Dim:=4 else if Sz>12 then Dim:=4
else Dim:=3; else Dim:=3;
@ -316,13 +316,21 @@ begin
end; end;
procedure TRobotField.DrawTag(x,y: integer); procedure TRobotField.DrawTag(x,y: integer);
var Sz,sz2: integer; var sz2: integer;
begin begin
Sz:=CellSize; var Sz:=CellSize;
if Sz>80 then sz2:=Sz div 2 - 4 var s2 := Sz div 2;
else if Sz>52 then sz2:=Sz div 2 - 3 {if Sz>172 then
else if Sz>12 then sz2:=Sz div 2 - 2 sz2:=S2 - 6
else sz2:=Sz div 2 - 1; 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) if (RobotX=x) and (RobotY=y)
then Brush.Color:=clLightGray then Brush.Color:=clLightGray
@ -417,10 +425,9 @@ begin
end; end;
procedure TRobotField.MoveRobot(x,y: integer); procedure TRobotField.MoveRobot(x,y: integer);
var vx,vy: integer;
begin begin
vx:=RobotX; var vx:=RobotX;
vy:=RobotY; var vy:=RobotY;
RobotX:=x; RobotX:=x;
RobotY:=y; RobotY:=y;
DrawCell(vx,vy); DrawCell(vx,vy);
@ -716,6 +723,8 @@ procedure MainWindowClose := SaveIni;
procedure buttonStartClick(o: Object; e: EventArgs); procedure buttonStartClick(o: Object; e: EventArgs);
begin begin
if t=nil then
exit;
if t.ThreadState = System.Threading.ThreadState.Suspended then if t.ThreadState = System.Threading.ThreadState.Suspended then
begin begin
robField.StepFlag := False; robField.StepFlag := False;
@ -733,6 +742,8 @@ end;
procedure buttonStepClick(o: Object; e: EventArgs); procedure buttonStepClick(o: Object; e: EventArgs);
begin begin
if t=nil then
exit;
robField.StepFlag := True; robField.StepFlag := True;
t.Resume; t.Resume;
(GraphABCControl as Control).Focus; (GraphABCControl as Control).Focus;
@ -768,12 +779,11 @@ begin
end; end;
procedure CorrectWHLT; procedure CorrectWHLT;
var mw,mh: integer;
begin begin
if (RobField.DimX=0) or (RobField.DimY=0) then if (RobField.DimX=0) or (RobField.DimY=0) then
exit; exit;
mw := (GraphABCControl.Width - 30) div RobField.DimX; var mw := (GraphABCControl.Width - 30) div RobField.DimX;
mh := (GraphABCControl.Height - 20) div RobField.DimY; var mh := (GraphABCControl.Height - 20) div RobField.DimY;
RobField.CellSize := min(mw,mh); RobField.CellSize := min(mw,mh);
if RobField.CellSize mod 2 = 1 then if RobField.CellSize mod 2 = 1 then
RobField.CellSize := RobField.CellSize - 1; RobField.CellSize := RobField.CellSize - 1;
@ -1106,6 +1116,7 @@ begin
Brush.Color := MainForm.BackColor; Brush.Color := MainForm.BackColor;
FillRectangle(0,0,1280,1024); FillRectangle(0,0,1280,1024);
Pen.RoundCap := True;
LoadIni(settings); LoadIni(settings);
MainForm.Invoke(SetWindowBounds, new System.Drawing.Rectangle(settings.Left,settings.Top,settings.Width,settings.Height)); 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); procedure buttonStartClick(o: Object; e: EventArgs);
begin begin
if t=nil then
exit;
if t.ThreadState = System.Threading.ThreadState.Suspended then if t.ThreadState = System.Threading.ThreadState.Suspended then
begin begin
DMField.StepFlag := False; DMField.StepFlag := False;
@ -604,6 +606,8 @@ end;
procedure buttonStepClick(o: Object; e: EventArgs); procedure buttonStepClick(o: Object; e: EventArgs);
begin begin
if t=nil then
exit;
DMField.StepFlag := True; DMField.StepFlag := True;
t.Resume; t.Resume;
(GraphABCControl as Control).Focus; (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'; 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'; SEEKEOLN_FOR_TEXT_WRITEOPENED = 'Функция SeekEoln не может быть вызвана для текстового файла, открытого на запись!!SeekEoln function can''t be called for file, opened on writing';
BAD_TYPE_IN_RUNTIMESIZEOF = 'Bad Type in RunTimeSizeOf'; BAD_TYPE_IN_RUNTIMESIZEOF = 'Bad Type in RunTimeSizeOf';
PARAMETER_COUNT_MUST_BE_GREATER_0 = 'Параметр count должен быть > 0!!Parameter count must be > 0'; PARAMETER_MUST_BE_GREATER_EQUAL_0 = 'Параметр должен быть >= 0!!Parameter must be >= 0';
PARAMETER_COUNT_MUST_BE_GREATER_1 = 'Параметр count должен быть > 1!!Parameter count must be > 1'; 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_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_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'; 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; function SeqGen<T>(count: integer; first: T; next: T->T): sequence of T;
begin begin
if count < 1 then 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); Result := Iterate(first, next).Take(count);
end; end;
function SeqGen<T>(count: integer; first, second: T; next: (T,T) ->T): sequence of T; function SeqGen<T>(count: integer; first, second: T; next: (T,T) ->T): sequence of T;
begin begin
if count < 1 then 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); Result := Iterate(first, second, next).Take(count);
end; end;
@ -4129,7 +4130,7 @@ end;
function ArrGen<T>(count: integer; first: T; next: T->T): array of T; function ArrGen<T>(count: integer; first: T; next: T->T): array of T;
begin begin
if count < 1 then 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]; var a := new T[count];
a[0] := first; a[0] := first;
for var i := 1 to a.Length - 1 do 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; function ArrGen<T>(count: integer; first, second: T; next: (T,T) ->T): array of T;
begin begin
if count < 2 then 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]; var a := new T[count];
a[0] := first; a[0] := first;
a[1] := second; a[1] := second;
@ -8728,14 +8729,73 @@ end;
/// Возвращает последние count элементов последовательности /// Возвращает последние count элементов последовательности
function TakeLast<T>(Self: sequence of T; count: integer): sequence of T; extensionmethod; function TakeLast<T>(Self: sequence of T; count: integer): sequence of T; extensionmethod;
begin 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; end;
{function TakeLast<T>(Self: sequence of T; count: integer): sequence of T; extensionmethod;
begin
Result := Self.Reverse.Take(count).Reverse;
end;}
/// Возвращает последовательность без последних count элементов /// Возвращает последовательность без последних 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 begin
Result := Self.Reverse.Skip(count).Reverse; 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; 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)); raise new ArgumentException(GetTranslation(PARAMETER_STEP_MUST_BE_NOT_EQUAL_0));
if count < 0 then 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 if (from < 0) or (from > Len - 1) then
raise new ArgumentException(GetTranslation(PARAMETER_FROM_OUT_OF_RANGE)); raise new ArgumentException(GetTranslation(PARAMETER_FROM_OUT_OF_RANGE));

View file

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