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

 
Dmitry Fedoseev:

It's kindergarten.

From your side so exactly. Try to process the same code with double parameters (you can normalise anything).

Maybe in the process you will understand what I mean.

 
Stanislav Dray:

From your side so exactly. Try to process the same code with double parameters (you can normalise anything).

Maybe in the process you will understand what I was talking about.

No, I can assure you, responsibly, that you do not understand something here.

 
Dmitry Fedoseev:

No, I can assure you, responsibly, that there's something you don't understand here.

Well then, good luck in normalising the arrays :)

 
Stanislav Dray:

Well then, good luck in normalising the arrays :)

With this approach, it's you who should hope for luck.

 

You are actually doing some bullshit. The cost of filtration is c*O (n). Where c is some constant for extras. It is miserable. Since you cannot improve O(n), you have decided to use c. Why? It is insignificant. Any optimization you do will only improve a part of this negligible correction.

You'd better check if all the submitted algorithms really have O(n). None of them have been tested.

 
Vasiliy Sokolov:

It is negligible. Any optimization you do will only improve a fraction of this negligible correction.

Well, Semko proved the opposite - he improved the standard search algorithm by more than two(!) times.

Surprisingly, it's a good branch.

 
TheXpert:

Well, I don't know, but Semko proved the opposite - he improved the standard search algorithm by more than two(!) times.

Surprisingly good branch turned out

It turns out that blockwise copying for "big" sequence is faster in spite of all overhead of internal ArrayCopy implementation.
I wonder, is there any way to use "speculative execution" to explicitly speed up the algorithm, or has it already fully affected the result?

 

Sergey Dzyublik , no offence, just for information. I downloaded your file and felt compelled to see my function. You don't need unnecessary checks.
Was:

template<typename T>
int arrayFilter2(T &data[],const T value) // вариан Nikitin
  {
   int d=ArraySize(data),j=0,y=0;

   for(int i=0; i<d; i++,y++)
     {
      bool res=false;
      if(data[i]==value)// || data[i]==NULL)
        {
         res=true;
         j++;
        }

      if(j>0)
        {
         if(d==y+j)
            break;
         data[y]=data[y+j];
        }
      if(res)
         y--;
     }

   if(d>y)
      ArrayResize(data,y);

   return y;
  }

Became:

template<typename T>
int arrayFilter2(T &data[],const T value=NULL)
  {
     int s, _s = s = ArraySize(data);
     bool res = false;
     
     for(int i=0, j=0; i<_s; i++,j++)
     {
          if( data[i] == value)// || data[i]==NULL)
          {
               res = true;
               s--;
               j--;
               continue;
          }
          if( res )
               data[j] = data[i];
     }
     
     if(s < _s)
          ArrayResize(data, s);
     
     return s;
  }
Files:
 
Konstantin Nikitin:

Sergey Dzyublik , no offence, just for information. I downloaded your file and felt compelled to see my function. No need for unnecessary checks.
I had:

Became:

Why did you fix yourself and throw me out? It's no good.

 
Konstantin Nikitin:

Sergey Dzyublik , no offence, just for information.
I downloaded your file and felt compelled to see my function.

The last available file was used, no edits were made to the code from the comments.