Clearing an array of defined element(s) - page 9

 
Nikolai Semko:
In essence, all algorithms are the same. Everyone modifies the array element by element, and everyone strives for Fedoseev's variant, because it does not have anything unnecessary.
Only in my case, it is done in blocks using ArrayCopy, so there is a speed advantage.

And what about Pyotr? Has everyone "torn up"? Nobody put his code in the checker. I wonder how, and to what extent, he blew everyone away on the board.

 
Vladimir:

I thought about the reasons and corrected two lines in it to remove one third of elements, not 0.1%.

Conclusion: calculating addresses in an array with an arbitrary distance between their numbers is still worse than processing items in a row at a given step, all the more so at step 1, the compiler can optimize it.

Oh, I see what you mean. Somehow I missed this phrase
Yes, of course it's clear, but still, even when I have to throw out every third element (then ArrayCopy stops working for me and winnings disappear) the picture is different:

2018.11.13 13:46:01.524 ArrayDeleteValue (EURUSD,D1)    вариант Pastushak: Контрольная сумма = 332864; элементов - 667202; время выполнения = 66640 микросекунд
2018.11.13 13:46:01.531 ArrayDeleteValue (EURUSD,D1)    вариант Korotky:   Контрольная сумма = 332864; элементов - 667202; время выполнения = 5932 микросекунд
2018.11.13 13:46:01.537 ArrayDeleteValue (EURUSD,D1)    вариант Fedoseev:  Контрольная сумма = 332864; элементов - 667202; время выполнения = 5142 микросекунд
2018.11.13 13:46:01.544 ArrayDeleteValue (EURUSD,D1)    вариант Semko:     Контрольная сумма = 332864; элементов - 667202; время выполнения = 5831 микросекунд
2018.11.13 13:46:01.552 ArrayDeleteValue (EURUSD,D1)    вариант Nikitin:   Контрольная сумма = 332864; элементов - 667202; время выполнения = 5493 микросекунд
2018.11.13 13:46:01.563 ArrayDeleteValue (EURUSD,D1)    вариант Vladimir:  Контрольная сумма = 958449; элементов - 667202; время выполнения = 11026 микросекунд

Pavlov's variant really doesn't work, but you also have correct and incorrect checksum.

Files:
 
Artyom Trishkin:

And what about Peter? Did you tear them all apart? No one inserted his code into the checker. It's interesting how and to what extent he's blown everyone away on the board.

I still don't understand his flight of fancy. He still hasn't provided a ready-made function. And if I complete it for him, he'll accuse me again of re-doing everything. ))

 
Nikolai Semko:

I still don't understand his flight of fancy. He still hasn't provided a ready-made function. And if I complete it for him, he'll accuse me again of re-doing everything. ))

Well, looking at his code from a mobile phone I had an impression that he writes in a "straightforward manner". That's why he didn't provide the function - he does everything in a row. And his script is not a function but straightforward code. Of course, such a script may not imply a function, but... I think he lacks goto for his flights :)

But that's just my feeling.

 
Nikolai Semko:

Fixed Pavlov's variant.
Your values are strange. Maybe you have run the script after profiling or debugging without recompiling the code?
That's how it works for me:

And in your variant it gives wrong checksum. Creation of an additional array is not profitable at all, on the contrary, it slows down the process and eats up additional resources.

Corrected.

int ArrayDelV(int &a[],const int val)
  { // вариант Vladimir
   bool Flags[]; // массив пометок на удаление
   int N,NewN,i,j;
   N=ArraySize(a);
   ArrayResize(Flags,N);
   if (ArrayInitialize(Flags,false)!=N) return(-1);
   NewN=N; // Сколько останется
   for(i=0;i<N;i++) {if(a[i]==val) {Flags[i]=true; NewN--;}}
   j=0;
   for(i=0;i<N;i++) {if(!Flags[i]) {a[j]=a[i]; j++;}}
   ArrayResize(a,NewN);
   return(NewN);
  }

I've run it a few times, the results are dangling - computer's really busy, won't be free until Saturday. Better check with someone else. But the checksum now matches. For highly sparse unnecessary values (0.1%)

2018.11.13 21:35:16.888 del_2 (GBPUSD.m,H1) option Pastushak: Checksum = 497057781; elements - 998984; execution time = 418662 microseconds
2018.11.13 21:35:16.898 del_2 (GBPUSD.m,H1) variant Korotky: Checksum = 497057781; elements - 998984; execution time = 10683 microseconds
2018.11.13 21:35:16.918 del_2 (GBPUSD.m,H1) variant Fedoseev: Checksum = 497057781; elements - 998984; execution time = 9740 microseconds
2018.11.13 21:35:16.928 del_2 (GBPUSD.m,H1) variant Semko: Checksum = 497057781; elements - 998984; execution time = 4691 microseconds
2018.11.13 21:35:16.944 del_2 (GBPUSD.m,H1) variant Pavlov: Checksum = 497057781; elements - 998984; execution time = 12512 microseconds
2018.11.13 21:35:16.957 del_2 (GBPUSD.m,H1) variant Nikitin: Checksum = 497057781; elements - 998984; execution time = 10720 microseconds
2018.11.13 21:35:16.978 del_2 (GBPUSD.m,H1) variant Vladimir: Checksum = 497057781; elements - 998984; execution time = 17197 microseconds

for one third

2018.11.13 21:57:17.838 del_2 (GBPUSD.m,H1) variant Pastushak: Checksum = 668222; elements - 667065; execution time = 65732 microseconds
2018.11.13 21:57:17.838 del_2 (GBPUSD.m,H1) variant Korotky: Checksum = 668222; elements - 667065; execution time = 4757 microseconds
2018.11.13 21:57:17.848 del_2 (GBPUSD.m,H1) variant Fedoseev: Checksum = 668222; elements - 667065; execution time = 4815 microseconds
2018.11.13 21:57:17.858 del_2 (GBPUSD.m,H1) variant Semko: Checksum = 668222; elements - 667065; execution time = 5812 microseconds
2018.11.13 21:57:17.858 del_2 (GBPUSD.m,H1) variant Pavlov: Checksum = 1001157; elements - 667065; execution time = 0 microseconds
2018.11.13 21:57:17.858 del_2 (GBPUSD.m,H1) variant Nikitin: Checksum = 668222; elements - 667065; execution time = 4749 microseconds
2018.11.13 21:57:17.868 del_2 (GBPUSD.m,H1) variant Vladimir: Checksum = 668222; elements - 667065; execution time = 9814 microseconds
Pavlov has crashed again.

My conclusion about speeding up loop for loops is probably incorrect for MQL languages.

And creating an additional array should reduce the duration of the transaction itself by removing the superfluous ones, keeping the array unchanged until the necessary moment of its start. So far, there's been no talk of data integrity here.

 
Artyom Trishkin:

What about Peter? Did he "tear up" everyone? Nobody put his code in the checker. I wonder how, and to what extent, he blew everyone away on the board.

But I've managed to get a hold of Peter's version.

int PeterArray(int &Arr[],const int val) // вариант Peter Konov
  {
   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,q);
   return (q);
  }

It's quite compact and even works correctly. Kudos to Pyotr.
But in terms of speed he ranks second from the end. Or first place from the end if you don't count the original, completely unsuitable for speed version of the owner of this thread.

2018.11.13 14:08:32.857 ArrayDeleteValue (EURUSD,D1)    вариант Pastushak: Контрольная сумма = 495882514; элементов - 999010; время выполнения = 150492 микросекунд
2018.11.13 14:08:32.861 ArrayDeleteValue (EURUSD,D1)    вариант Korotky:   Контрольная сумма = 495882514; элементов - 999010; время выполнения = 2441 микросекунд
2018.11.13 14:08:32.865 ArrayDeleteValue (EURUSD,D1)    вариант Fedoseev:  Контрольная сумма = 495882514; элементов - 999010; время выполнения = 1852 микросекунд
2018.11.13 14:08:32.867 ArrayDeleteValue (EURUSD,D1)    вариант Semko:     Контрольная сумма = 495882514; элементов - 999010; время выполнения = 779 микросекунд
2018.11.13 14:08:32.871 ArrayDeleteValue (EURUSD,D1)    вариант Nikitin:   Контрольная сумма = 495882514; элементов - 999010; время выполнения = 2374 микросекунд
2018.11.13 14:08:32.876 ArrayDeleteValue (EURUSD,D1)    вариант Vladimir:  Контрольная сумма = 495882514; элементов - 999010; время выполнения = 3720 микросекунд
2018.11.13 14:08:32.885 ArrayDeleteValue (EURUSD,D1)    вариант Peter:     Контрольная сумма = 495882514; элементов - 999010; время выполнения = 7266 микросекунд
Files:
 

:-) if you don't try to keep the order, the time is O(1) , the total number of steps of all the loops= array size

too lazy to code :-)

1. Search for first 3 from left to right.

2. if found, then look for a non-three from right to left, copy it to the place of the 3.

continue until 1,2 have intersected, trim the array by the number of copies.

ideally, it is exactly 1/2 of"bubble sorting" :-) if, instead of copying, you make a swap, the output will be a partially ordered array (all 3-thirds moved to the right)

 
Реter Konow:

More refinement:

Sorry, they say you're a good marketer, but a programmer... even worse than me.

1. The internal integer variable is not initialized, so it will be zero, but not guaranteed. In the loop, the shift backwards will not happen (the first time) for two reasons at once - guess which one.

2. (most importantly) you first shift the array elements, then increase the value of the deleted variable, and then there will be a loop and the next shift will happen one more than necessary. In other words, your code will avalanche the original array.

 
Extreme options:
There are no extra elements in the array:
2018.11.13 14:44:33.512 ArrayDeleteValue (EURUSD,D1)    вариант Pastushak: Контрольная сумма = 496983086; элементов - 1000000; время выполнения = 137515 микросекунд
2018.11.13 14:44:33.514 ArrayDeleteValue (EURUSD,D1)    вариант Korotky:   Контрольная сумма = 496983086; элементов - 1000000; время выполнения = 1408 микросекунд
2018.11.13 14:44:33.517 ArrayDeleteValue (EURUSD,D1)    вариант Fedoseev:  Контрольная сумма = 496983086; элементов - 1000000; время выполнения = 1807 микросекунд
2018.11.13 14:44:33.519 ArrayDeleteValue (EURUSD,D1)    вариант Semko:     Контрольная сумма = 496983086; элементов - 1000000; время выполнения = 672 микросекунд
2018.11.13 14:44:33.522 ArrayDeleteValue (EURUSD,D1)    вариант Nikitin:   Контрольная сумма = 496983086; элементов - 1000000; время выполнения = 1433 микросекунд
2018.11.13 14:44:33.527 ArrayDeleteValue (EURUSD,D1)    вариант Vladimir:  Контрольная сумма = 496983086; элементов - 1000000; время выполнения = 4025 микросекунд
2018.11.13 14:44:33.533 ArrayDeleteValue (EURUSD,D1)    вариант Peter:     Контрольная сумма = 496983086; элементов - 1000000; время выполнения = 4297 микросекунд
The array has all unnecessary elements:
2018.11.13 14:47:15.338 ArrayDeleteValue (EURUSD,D1)    вариант Pastushak: Контрольная сумма = 2000000000; элементов - 0; время выполнения = 2093 микросекунд
2018.11.13 14:47:15.341 ArrayDeleteValue (EURUSD,D1)    вариант Korotky:   Контрольная сумма = 0; элементов - 0; время выполнения = 2257 микросекунд
2018.11.13 14:47:15.343 ArrayDeleteValue (EURUSD,D1)    вариант Fedoseev:  Контрольная сумма = 0; элементов - 0; время выполнения = 1078 микросекунд
2018.11.13 14:47:15.345 ArrayDeleteValue (EURUSD,D1)    вариант Semko:     Контрольная сумма = 0; элементов - 0; время выполнения = 665 микросекунд
2018.11.13 14:47:15.348 ArrayDeleteValue (EURUSD,D1)    вариант Nikitin:   Контрольная сумма = 0; элементов - 0; время выполнения = 1580 микросекунд
2018.11.13 14:47:15.353 ArrayDeleteValue (EURUSD,D1)    вариант Vladimir:  Контрольная сумма = 0; элементов - 0; время выполнения = 4064 микросекунд
2018.11.13 14:47:15.362 ArrayDeleteValue (EURUSD,D1)    вариант Peter:     Контрольная сумма = 0; элементов - 0; время выполнения = 7982 микросекунд
Files:
 
Алексей Тарабанов:

Sorry, they say you're a good marketer, but a programmer... even worse than me.


Alexei, you're killing a young talent...

this marketer hasn't been able to start selling for 5 years...and you say he's even worse as a programmer :-)

Reason: