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

 

Here is the best version, using binary search.

#include <Arrays\ArrayInt.mqh>
int array_filter(int &arr[], const int &filters[])
{
   int size_arr = ArraySize(arr);
   CArrayInt filterz;
   filterz.AssignArray(filters);
   filterz.Sort();
   int i=0, k=0;
   for(i=0; i<size_arr; i++)
      if(filterz.Search(arr[i]) < 0)
         arr[k++] = arr[i]; 
   return ArrayResize(arr, k); 
}


I don't speak Russian, I use google translate.
 
jdjahfkahjf:

He's not Russian, it's hard to understand. El habla espanol.

I was tempted to learn Spanish when I was passing through there, but I gave it up...for nothing.
 
template<typename T>
int arrayFilter(T &data[], const T value)
{
     bool ser = ArrayGetAsSeries( data ) ? ArraySetAsSeries(data, false) : false;
   
     int s, _s = s = ArraySize(data);
     bool result = false;
     
     for(int i=0, j=0; i<_s && !IsStopped(); i++)
     {
          if( data[i] == value || data[i] == NULL )
          {
               result = true;
               s--;
               continue;
          }
          
          if( result )
               data[j] = data[i];
          j++;
     }
     
     if(s < _s)
          if( ArrayResize(data, s) )
               if(ArraySize(data) == _s)
                    ArrayFill(data, s, _s-s, NULL);
     
     if( ser )
          ArraySetAsSeries(data, true);
     
     return s;
}

template<typename T>
int arrayFilter(T &data[], const T &value[])
{
     bool ser = ArrayGetAsSeries( data ) ? ArraySetAsSeries(data, false) : false;
   
     int s, _s = s = ArraySize(data);
     bool result = false;
     
     for(int i=0, j=0; i<_s && !IsStopped(); i++)
     {
          bool p = false;
          for(int y=0; y<ArraySize(value); y++)
               if( data[i] == value[y] )
               {
                    result = true;
                    s--;
                    p = true;
                    break;
               }
          if( p )
               continue;
          
          if( result )
               data[j] = data[i];
          j++;
     }
     
     if(s < _s)
          if( ArrayResize(data, s) )
               if(ArraySize(data) == _s)
                    ArrayFill(data, s, _s-s, NULL);
     
     if( ser )
          ArraySetAsSeries(data, true);
     
     return s;
}

How you need it is how you can summon it in the end.

 
Konstantin Nikitin:

How you need it is how you can summon it in the end.

a copy of value[] to be sorted when entering the function and

the binary search will be faster, the Spaniard is right here.

 
Maxim Kuznetsov:

a copy of value[] to be sorted when entering the function and

the binary search will be faster, the Spaniard is right about that.

I didn't bother myself with it. I just did a quick transfer. Yes, and there may be string arrays.

P.S. I'm fed up with this entertainment. It's time to get down to business.
 
Maxim Kuznetsov:

a copy of value[] to be sorted when entering the function and

the binary search will be faster, the Spaniard is right about that.

I would use HashSet data structure for value.
Complexity would be O(n) + O(m).

For the proposed binary search, the complexity would be: O(n log(m))

 

24 pages - I don't understand where the temperament comes from and how much you can go through a primitive task, took the script from the third page, as there is no strength to read further, added three lines, inline without functions.

N=ArraySize(arr)-1;
for(int i=N;i>=0;i--) if(arr[i]==Value) arr[i]=arr[N--]; N++;
ArrayResize(arr,N);
2018.11.17 01:44:40.077 ArrayDeleteValue (EURUSD,H1)    вариант Pastushak: Контрольная сумма = 496597320; элементов - 999020; время выполнения = 308973 микросекунд
2018.11.17 01:44:40.092 ArrayDeleteValue (EURUSD,H1)    вариант Korotky: Контрольная сумма = 496597320; элементов - 999020; время выполнения = 11531 микросекунд
2018.11.17 01:44:40.107 ArrayDeleteValue (EURUSD,H1)    вариант Fedoseev: Контрольная сумма = 496597320; элементов - 999020; время выполнения = 11325 микросекунд
2018.11.17 01:44:40.114 ArrayDeleteValue (EURUSD,H1)    вариант Semko: Контрольная сумма = 496597320; элементов - 999020; время выполнения = 2819 микросекунд
2018.11.17 01:44:40.117 ArrayDeleteValue (EURUSD,H1)    вариант Inline: Контрольная сумма = 496597320; элементов - 999020; время выполнения = 2600 микросекунд

it's strange, but it looks like he beat everyone - "in five minutes and without any tricks" (c) and went to bed...))

Files:
 
Ivan Negreshniy:

24 pages - I don't understand where the temperament comes from and how much you can go through a primitive task, took the script from the third page, as there is no strength to read further, added three lines, inline without functions.

it's strange, but it looks like I beat everyone - "in five minutes and no tricks" (c) and went to bed...)))

1. You took code of unknown age, and this is direct disrespect to community;
2. You made changes in code, nagamno-coding somewhere inside, without even putting them into separate function;
3. Then, apparently, you launched the code for performance testing in DEBUG compilation, as both speed of execution and results do not correspond to RELEASE version.
4. Your code contains errors and does not solve the problem at all. (Sincearr[N--] may contain aValue which was neither filtered nor deleted).

But with pathos from such "winner"...

 

OK. As long as there is no work, the crazy test continues. I have added new vector test and included@Ivan Negreshniy option at the same time, look, sort out your mistakes, your algorithm is not working.

We got this

1

Files:
 

Minor optimisation

P.S. corrected errors and replaced the file

Files: