nick048:

My question is:

it is possible to write better this function (see i.e. the 3 IF)?

It really depends how much freedom you want with the algorithm. Something

like the following would give you a lot of freedom:

#include <cassert>

void IncCounters(unsigned *const *ppcounters,

int const val,

int const *const *ppcols,

unsigned const quant_cols,

unsigned const num_per_col)

{

assert(ppcounters);

assert(ppcols);

assert(quant_cols);

assert(num_per_col);

int const *const *const ppcols_over = ppcols + quant_cols;

do

{

unsigned *const pcounter = *ppcounters++; assert(pcounter);

int const *pelem = *ppcols++; assert(pelem);

int const *const pelem_over = pelem + num_per_col;

do if (val == *pelem++) ++*pcounter;

while (pelem_over != pelem);

} while (ppcols_over != ppcols);

}

int main()

{

int const column1[12] = {1,2,3,4,5,6,7,8,9,10,11,12};

int const column2[12] = {1,2,4,8,16,32,65,128,256,512,1024,2048};

int const column3[12] = {1,2,3,5,7,11,13,17,19,50,60,70};

int const *const arr_pcols[3] = {column1,column2,column3};

unsigned counter1=0, counter2=0, counter3=0;

unsigned *const arr_pcounters[3] = {&counter1,&counter2,&counter3};

IncCounters(arr_pcounters,2,arr_pcols,3,12);

}

--

Frederick Gotham