the most frequent value from a number of buffers?

 

Say you have 10 buffers:

buf1[i] =icustom(0,0,"someIndicator",10,0,i);

buf2[i] =icustom(0,0,"someIndicator",20,0,i);

buf3[i] =icustom(0,0,"someIndicator",30,0,i);

...

buf10[i] =icustom(0,0,"someIndicator",100,0,i);

So it's the same custom indicator, but only its window length is changing from 10 to 100. Assume these 10 values are integers and often close to or equivalent to each other. Say the 10 buffers have the following values: 12,10,8,12,12,4,12,4,12,12. The most frequent element in this list is obviously 12. How would you code this in an efficient way that some summary buffer contains the value of 12 for the current bar?

 
Assuming the int values range 0 to 100
int count[101]; for(int iCnt=0; iCnt<=100; iCnt++) count[iCnt]=0;
count[ buf1[i] ]++;
count[ buf2[i] ]++;
:
count[ buf10[i] ]++;
int max=0; for(int iCnt=0; iCnt<=100; iCnt++) if (max < count[iCnt]){ 
   max = count[iCnt];
   MostFrequentInt[i] = iCnt;
}
if bufX are really doubles then use
int value = buf1[i]; count[ value ]++;
    value = buf2[i]; count[ value ]++;
:
 
WHRoeder:
Assuming the int values range 0 to 100 if bufX are really doubles then use

thx WHRoeder!