This is the problem I ran into long time ago.
I thought I may ask your for your ideas.
assume I have very small list of numbers (integers), 4 or 8 elements, that need to be sorted, fast.
what would be the best approach/algorithm?
my approach was to use the max/min functions (10 functions to sort 4 numbers, no branches, iirc).
// s(i,j) == max(i,j), min(i,j)
i,j = s(i,j)
k,l = s(k,l)
i,k = s(i,k) // i on top
j,l = s(j,l) // l on bottom
j,k = s(j,k)
I guess my question pertains more to implementation, rather than type of algorithm.
At this point it becomes somewhat hardware dependent , so let us assume Intel 64-bit processor with SSE3 .
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…