src/plugin/radixSort.c
int RadixSortIndexPass (
    size_t *x,
    size_t *index,
    const size_t N,
    const size_t exp,
    const size_t shift)
{
    // Allocate space for x, index copies and x mod
    size_t *xmod = calloc(N, sizeof *xmod);
    size_t *outx = calloc(N, sizeof *outx);
    size_t *outi = calloc(N, sizeof *outi);
    int i, c, count[shift];

    if ( xmod == NULL ) return(sf_oom_error("RadixSortIndexPass", "xmod"));
    if ( outx == NULL ) return(sf_oom_error("RadixSortIndexPass", "outx"));
    if ( outi == NULL ) return(sf_oom_error("RadixSortIndexPass", "outi"));

    // Initialize count as 0s
    for (i = 0; i < shift; i++)
        count[i] = 0;

    // Freq count of ((x / exp) mod shift)
    for (i = 0; i < N; i++) {
        count[ xmod[i] = ((outx[i] = x[i]) / exp) % shift ]++;
        outi[i] = index[i];
    }

    // Cummulative freq count (position in output)
    for (i = 1; i < shift; i++)
        count[i] += count[i - 1];

    // Copy back in stable sorted order
    for (i = N - 1; i >= 0; i--) {
        index[c = count[xmod[i]]-- - 1] = outi[i];
        x[c] = outx[i];
    }

    // Free space
    free(xmod);
    free(outx);
    free(outi);

    return(0);
}
/**
 * @brief One pass of radix sort: Counting sort with index
 *
 * Perform one pass of the counting sort for the radix sort using
 * the modulus operator to sort log2(shift) bits at a time.
 *
 * @param x vector of unsigned 64-bit integers to sort
 * @param index vector of same length where to store the sort index
 * @param N length of array
 * @param exp the jth step gives exp = 2^(d * (j - 1))
 * @param shift number of bits to sort at a time (equal to 2^d)
 * @return jth pass of radix sort for @x and corresponding @index
 */
@brief One pass of radix sort: Counting sort with index
Perform one pass of the counting sort for the radix sort using
the modulus operator to sort log2(shift) bits at a time.


@brief One pass of radix sort : Counting sort with index Perform one pass of the counting sort for the radix sort using the modulus operator to sort log2 ( shift ) bits at a time .
int RadixSortIndexPass (
    size_t *x,
    size_t *index,
    const size_t N,
    const size_t exp,
    const size_t shift)
{
    size_t *xmod = calloc(N, sizeof *xmod);
    size_t *outx = calloc(N, sizeof *outx);
    size_t *outi = calloc(N, sizeof *outi);
    int i, c, count[shift];
    if ( xmod == NULL ) return(sf_oom_error("RadixSortIndexPass", "xmod"));
    if ( outx == NULL ) return(sf_oom_error("RadixSortIndexPass", "outx"));
    if ( outi == NULL ) return(sf_oom_error("RadixSortIndexPass", "outi"));
    for (i = 0; i < shift; i++)
        count[i] = 0;
    for (i = 0; i < N; i++) {
        count[ xmod[i] = ((outx[i] = x[i]) / exp) % shift ]++;
        outi[i] = index[i];
    }
    for (i = 1; i < shift; i++)
        count[i] += count[i - 1];
    for (i = N - 1; i >= 0; i--) {
        index[c = count[xmod[i]]-- - 1] = outi[i];
        x[c] = outx[i];
    }
    free(xmod);
    free(outx);
    free(outi);
    return(0);
}
int RadixSortIndexPass ( size_t * x , size_t * index , const size_t N , const size_t exp , const size_t shift ) { size_t * xmod = calloc ( N , sizeof * xmod ) ; size_t * outx = calloc ( N , sizeof * outx ) ; size_t * outi = calloc ( N , sizeof * outi ) ; int i , c , count [ shift ] ; if ( xmod == NULL ) return ( sf_oom_error ( " " , " " ) ) ; if ( outx == NULL ) return ( sf_oom_error ( " " , " " ) ) ; if ( outi == NULL ) return ( sf_oom_error ( " " , " " ) ) ; for ( i = 0 ; i < shift ; i ++ ) count [ i ] = 0 ; for ( i = 0 ; i < N ; i ++ ) { count [ xmod [ i ] = ( ( outx [ i ] = x [ i ] ) / exp ) % shift ] ++ ; outi [ i ] = index [ i ] ; } for ( i = 1 ; i < shift ; i ++ ) count [ i ] += count [ i - 1 ] ; for ( i = N - 1 ; i >= 0 ; i -- ) { index [ c = count [ xmod [ i ] ] -- - 1 ] = outi [ i ] ; x [ c ] = outx [ i ] ; } free ( xmod ) ; free ( outx ) ; free ( outi ) ; return ( 0 ) ; }
@brief One pass of radix sort: Counting sort with index
 Perform one pass of the counting sort for the radix sort using
 the modulus operator to sort log2(shift) bits at a time.
@brief One pass of radix sort : Counting sort with index Perform one pass of the counting sort for the radix sort using the modulus operator to sort log2 ( shift ) bits at a time .
// Allocate space for x, index copies and x mod // Initialize count as 0s // Freq count of ((x / exp) mod shift) // Cummulative freq count (position in output) // Copy back in stable sorted order // Free space