Another nuance. I have proved that my algorithm works correctly. I printed out the values that I got after the function was executed. How well the other algorithms work is a mystery.
ZS. You did make one mistake when writing the function according to my solution, though:
My function is not
а
But thanks anyway.
No, I didn't make a mistake, I corrected yours. Think well, what does your line do? Just try and change it and you'll see. It will be the wrong checksum and the wrong size.
Nikolai Semko: No, I didn't make a mistake, I corrected yours. Think well, what does your line do? It doesn't do anything. Just try and change it and you'll see. It will be the wrong checksum and the wrong size.
The result is exactly the same. There is no error.
Yes, it doesn't do anything. But it makes more sense with it. ))
//+------------------------------------------------------------------+//| Erase and Resize.mq5 |//| Peter Konow |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Peter Konow"#property link"https://www.mql5.com"#property version"1.00"//--------------------------------------------------------------------//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
int Arr[20] = {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2};
ulong q1 = GetMicrosecondCount();
//--------------------------------
PeterArray(Arr,3);
//--------------------------------ulong q2 = GetMicrosecondCount();
//--------------------------------Print("Array new size ",ArraySize(Arr)," Тime of operation ",q2-q1);
ArrayPrint(Arr);
}
//+------------------------------------------------------------------+//+------------------------------------------------------------------+int PeterArray(int &Arr[],int val) // вариант Peter Konow
{
int deleted=0,q=0;
for(int a1=0; a1<ArraySize(Arr); a1++)
{
if(deleted)Arr[q]=Arr[q+deleted];
if(Arr[q]==val){deleted++; q--;}
q++;
}
ArrayResize(Arr,ArraySize(Arr) - deleted);
return (q);
}
//+------------------------------------------------------------------+
This calls into question the validity of the checksum checking algorithms. So, when we calculate the checksum, we make a loop through the array that still keeps its previous elements?
I suggest checking the algorithms my way. By outputting an array of 20 values.
Question. Why in this code, after changing the size of the array, it still prints the same as before the change?
This calls into question the validity of the checksum checking algorithms. So, when we calculate the checksum, we make a loop through the array that still keeps its previous elements?
I suggest checking the algorithms my way. By outputting an array of 20 values.
This will be a test of correctness, not speed.
I suggest a million, as there are a million in the test. Let everyone sit and compare.))
I figured it out, it was the field shift in the structure, not the whole structure...
If the structure is a simple type, it should work.
Another nuance. I have proved that my algorithm works correctly. I printed out the values that I got after the function was executed. How well the other algorithms work is a mystery.
The checksum seems to prove correct though.
ZS. You did make one mistake when writing the function according to my solution, though:
My function is not
а
But thanks anyway.
ZS. You did make one mistake when writing the function according to my solution, though:
My function is not
а
in your code it's the same as
No, I didn't make a mistake, I corrected yours. Think well, what does your line do? It doesn't do anything. Just try and change it and you'll see. It will be the wrong checksum and the wrong size.
The result is exactly the same. There is no error.
Yes, it doesn't do anything. But it makes more sense with it. ))
in your code, it equals
Yes.
Yes.
Oh yeah, sorry.
I remembered.
Your code was taken from here.
Your line wasn't there and I remember that line I had to add to make it work properly.
But it makes more sense with it. ))
There's an extra mathematical operation in it. ))
Question. Why in this code, after changing the size of the array, it still prints the same as before the change?
This calls into question the validity of the checksum checking algorithms. So, when we calculate the checksum, we make a loop through the array that still keeps its previous elements?
I suggest checking the algorithms my way. By outputting an array of 20 values.
This will be a check for correctness, not speed.Question. Why in this code, after changing the size of the array, it still prints the same as before the change?
This calls into question the validity of the checksum checking algorithms. So, when we calculate the checksum, we make a loop through the array that still keeps its previous elements?
I suggest checking the algorithms my way. By outputting an array of 20 values.
This will be a test of correctness, not speed.I suggest a million, since there are a million in the test. Let all sit and compare))).
The checksum is not calculated correctly.
Check it yourself. It counts the elements that remain in the deleted part of the array.
Of course, this is not yet proof that the check is wrong, but there is already some doubt.
The checksum is calculated from the elements of that row:
And the last 6 elements were previously deletedby ArrayResize.
But the function still counts them anyway.