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

 
Yes... There are no limits to perfection.
 

Yeah... Monsters of programming...

Personally I would write about the same as @Dmitry Fedoseev, the most understandable and at the same time efficient code, respectively, the speed would be about the same.

I think @Nikolai Semko 's code is quite a serious perversion, but I think it should be useful. And I think it is right and good, if every millisecond is important.

 
Georgiy Merts:

Yeah... Monsters of programming...

Personally I would write about the same as @Dmitry Fedoseev, the most understandable and at the same time efficient code, respectively, the speed would be about the same.

I think @Nikolai Semko 's code is quite a serious perversion, but I think it should be useful. And I think it is right and good, if every millisecond is important.

I don't like that in both of these cases there is multiple dragging and dropping of the same item. It feels analogous to bubble sorting, which is the slowest in the vast majority of cases. It is simpler, clearer and more reliable to do as it is done in DMS: elements are marked for deletion (while counting how many are marked), then any unmarked (once) are moved to a new copy with the remaining number of array elements. In terms of memory, this will additionally only take up space for the flags array ("marked for deletion"), and the second, shortened copy of the array, together with the original one, will require no more memory than is needed for one ArrayResize. It's also possible to speed up flagging if it's not a single value that's being deleted, but an array, so you don't always have to run through all of its values. To do this, define a maximum and minimum in it (for strings this is also possible) and skip elements smaller than min or larger than max without marking.

 
Dmitry Fedoseev:

You've been getting in the puddle lately, just like in this thread )

Vladimir Pastushak:

show your variant of realization

Marketeer has already written variant, which I think is optimal, I do not see the sense in duplication, except that the size of the cycle take out
 
Dmitry Fedoseev:

That's better:

The best option, the speed measurements should confirm this.
 
TheXpert:

You've been getting into a puddle lately, just like in this thread.)

Marketeer has already written an option which I consider optimal, I see no point in duplicating it

Oh, you've been failing your doctoral thesis...

 
Vladimir:

I don't like the fact that in both of these cases there is multiple dragging and dropping of the same element.

In both cases, each element is dragged a maximum of once.
 
TheXpert:
One has 42 products, the other 6, the third 30. I'm afraid to imagine what an asshole there is inside with such questions and answers

The "expert" is great! He has lit up the audience by exposing the charms of Market :-)) I may not be an expert, but I strongly disagree with Dmitry Fedoseyev personally...

 
Denis Kirichenko:

But personally, I strongly disagree with Dmitri Fedoseyev...

not to impose.

 
Purely on the task at hand. Delete value and empty
template<typename T>
int arrayFilter(T &data[], const T value)
{
     int s, d = s = ArraySize(data);
     
     for(int i=d-1; i>=0; i--)
          if(data[i] == value || data[i] == NULL)
          {
               s--;
               for(int j=i; j<s; j++)
                    data[j]=data[j+1];
          }
  
     if(d > s)
          ArrayResize(data, s);
     
     return s;
}

void OnStart()
{
     long array[] = {1, 2, 3, 6, 9, 5, 6, 3, 25, ,, 6, 8, NULL, 7, NULL, 4};
     Print( arrayFilter<long>(array, 3) );
}