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

 
Peter, you have a unique programming style. In short, you program in spite of, not because of.
 
Реter Konow:

Right. But how do we know that the algorithms provided do not leave any blank spaces? The checksum doesn't prove it. Neither does the number of elements. After all, the function counts the elements that were there before the array was resized.

You've hit on an implementation, though, fixing a bug in static arrays.

int arrayFilter2(int &Test[],const int value)
  {
   int s,_s=s=ArraySize(Test);
   bool result=false;

   for(int i=0,j=0; i<_s; i++,j++)
     {
      if(Test[i]==value)// || Test[i]==NULL)
        {
         result=true;
         s--;
         j--;
         continue;
        }
      if(result)
         Test[j]=Test[i];
     }

   if(s<_s)
      if(ArrayResize(Test,s))
         if(ArraySize(Test)==_s)
            ArrayFill(Test,s,_s-s,NULL);

   return s;
  }

Now if it's static, we clear the tail.

Files:
 
Реter Konow:

Right. But how do we know that the algorithms provided do not leave any blank spaces? The checksum doesn't prove it. Neither does the number of elements. After all, the function counts the elements that were there before the array was resized.

You should look at the latest versions of the code, not the first.
Such a checksum, which takes into account the sequence of elements in the array, has been used for a long time:

double ControlSumm(int &a[]) 
  {
   double sum=0;
   for(int i=0; i<ArraySize(a); i++) sum+=(double)a[i]/(i+1);
   return sum;
  }
 

corrected a mistake in the 3rd test and tweaked my function

Files:
 
Nikolai Semko:

You'd look at the latest versions of the code, not the first.
It's been a long time since such a checksum has been used, which takes into account the sequence of elements in the array:

You need a demonstrable proof of correctness. A row of 20 numbers is sufficient for this. If the algorithm passes this test, it can be tested for speed.

The test carried out is a blind test.

Perhaps all the algorithms work correctly, and perhaps the leaders will fall out of place.

 
Реter Konow:

You need a demonstrable proof of correctness. A row of 20 numbers is sufficient for this. If the algorithm passes this check, it can be tested for speed.

The goal of the checksum is not to ensure that the arrays are the same if the checksum is the same, but to ensure that they are different if the checksum is different.

 
Nikolai Semko:

The purpose of the checksum is not to ensure that the arrays are the same if the checksum is the same, but to ensure that they are different if the checksum is different.

Nikolai, it's not hard to use my example and check the algorithms with an array of 20 elements, is it? Just output in the results?

 
Реter Konow:

You need a demonstrable proof of correctness. A row of 20 numbers is sufficient for this. If the algorithm passes this test, it can be tested for speed.

The test carried out is a blind test.

Perhaps all the algorithms work correctly, and perhaps the leaders will leave their places.

If you don't trust the checksum, what's the problem?

 
Реter Konow:

Nikolai, it's not hard to use my example and check the algorithms with an array of 20 elements, is it? Just display it in the results?

With an array of 20 elements it is impossible to estimate the speed of the function. And that's the point of this thread.

 
Nikolai Semko:

With an array of 20 elements, it is impossible to estimate the speed of the function. And this is the point of this branch.

There is also a requirement for the algorithm - the correct placement of elements inside the array, after removing unnecessary elements. This check must have been performed first. Then there is a speed check.