diff --git a/magyarsort.h b/magyarsort.h index 5efb391..a5eff63 100644 --- a/magyarsort.h +++ b/magyarsort.h @@ -193,15 +193,30 @@ namespace MagyarSort { return radics[DSTART + i]; } + /** Helper for calcPrefixSums */ + template + struct PMagic2 : public PMagic2 { + inline __attribute__((always_inline)) PMagic2(COUNTER_TYP *radics, COUNTER_TYP *prev) + : PMagic2(radics, prev) { + // Again first the 0th digit because of parent constructors! + // This is a template-unrolled loop too + PrefixMagic(radics, prev, DIGIT); + } + }; + + /** Template recursion endpoint */ + template + struct PMagic2<-1, COUNTER_TYP> { + inline __attribute__((always_inline)) PMagic2(COUNTER_TYP *radics, COUNTER_TYP *prev) {} + }; + template static inline void calcPrefixSums(COUNTER_TYP *radics) noexcept { static thread_local COUNTER_TYP prev[DIGITS]; memset(prev, 0, sizeof(prev)); - for(int i = 0; i < DIGIT_RANGE; ++i) { - // This is a template-unrolled loop too - PrefixMagic(radics, prev, i); - } + // This is a template-unrolled loop too + PMagic2(radics, prev); } /** Recursive Functor: no class should be generated I think (compiler should be smart) */