src/plugin/radixSort.c
int CountingSortIndex (
    size_t *x,
    size_t *index,
    const size_t N,
    const size_t min,
    const size_t max)
{
    int i, s;
    size_t range = max - min + 1;

    // Allocate space for x, index copies and x mod
    size_t *xcopy = calloc(N, sizeof *xcopy);
    size_t *icopy = calloc(N, sizeof *icopy);
    int    *count = calloc(range + 1, sizeof *count);

    if ( xcopy == NULL ) return(sf_oom_error("mf_counting_sort_index", "xcopy"));
    if ( icopy == NULL ) return(sf_oom_error("mf_counting_sort_index", "icopy"));
    if ( count == NULL ) return(sf_oom_error("mf_counting_sort_index", "count"));

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

    // Freq count of x
    for (i = 0; i < N; i++) {
        count[ xcopy[i] = (x[i] + 1 - min) ]++;
        icopy[i] = index[i];
    }

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

    // Copy back in stable sorted order
    // for (i = N - 1; i >= 0; i--) {
    for (i = 0; i < N; i++) {
        index[ s = count[xcopy[i] - 1]++ ] = icopy[i];
        x[s] = xcopy[i] - 1 + min;
    }

    // Free space
    free (count);
    free (xcopy);
    free (icopy);

    return(0);
}
/**
 * @brief Counting sort with index
 *
 * Perform counting sort, additionally storing data shuffle
 * in index variable.
 *
 * @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
 * @return Counting sort on integer array.
 */
@brief Counting sort with index
Perform counting sort, additionally storing data shuffle
in index variable.

@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
@return Counting sort on integer array.
@brief Counting sort with index Perform counting sort additionally storing data shuffle in index variable . @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 @return Counting sort on integer array .
int CountingSortIndex (
    size_t *x,
    size_t *index,
    const size_t N,
    const size_t min,
    const size_t max)
{
    int i, s;
    size_t range = max - min + 1;
    size_t *xcopy = calloc(N, sizeof *xcopy);
    size_t *icopy = calloc(N, sizeof *icopy);
    int    *count = calloc(range + 1, sizeof *count);
    if ( xcopy == NULL ) return(sf_oom_error("mf_counting_sort_index", "xcopy"));
    if ( icopy == NULL ) return(sf_oom_error("mf_counting_sort_index", "icopy"));
    if ( count == NULL ) return(sf_oom_error("mf_counting_sort_index", "count"));
    for (i = 0; i < range + 1; i++)
        count[i] = 0;
    for (i = 0; i < N; i++) {
        count[ xcopy[i] = (x[i] + 1 - min) ]++;
        icopy[i] = index[i];
    }
    for (i = 1; i < range; i++)
        count[i] += count[i - 1];
    for (i = 0; i < N; i++) {
        index[ s = count[xcopy[i] - 1]++ ] = icopy[i];
        x[s] = xcopy[i] - 1 + min;
    }
    free (count);
    free (xcopy);
    free (icopy);
    return(0);
}
int CountingSortIndex ( size_t * x , size_t * index , const size_t N , const size_t min , const size_t max ) { int i , s ; size_t range = max - min + 1 ; size_t * xcopy = calloc ( N , sizeof * xcopy ) ; size_t * icopy = calloc ( N , sizeof * icopy ) ; int * count = calloc ( range + 1 , sizeof * count ) ; if ( xcopy == NULL ) return ( sf_oom_error ( " " , " " ) ) ; if ( icopy == NULL ) return ( sf_oom_error ( " " , " " ) ) ; if ( count == NULL ) return ( sf_oom_error ( " " , " " ) ) ; for ( i = 0 ; i < range + 1 ; i ++ ) count [ i ] = 0 ; for ( i = 0 ; i < N ; i ++ ) { count [ xcopy [ i ] = ( x [ i ] + 1 - min ) ] ++ ; icopy [ i ] = index [ i ] ; } for ( i = 1 ; i < range ; i ++ ) count [ i ] += count [ i - 1 ] ; for ( i = 0 ; i < N ; i ++ ) { index [ s = count [ xcopy [ i ] - 1 ] ++ ] = icopy [ i ] ; x [ s ] = xcopy [ i ] - 1 + min ; } free ( count ) ; free ( xcopy ) ; free ( icopy ) ; return ( 0 ) ; }
@brief Counting sort with index
 Perform counting sort, additionally storing data shuffle
 in index variable.
@brief Counting sort with index Perform counting sort additionally storing data shuffle in index variable .
// Allocate space for x, index copies and x mod // Initialize count as 0s // Freq count of x // Cummulative freq count (position in output) // Copy back in stable sorted order // for (i = N - 1; i >= 0; i--) { // Free space