viewing paste topic/4321- counting_sort | Athena

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
prontera,158,188,5  script  test counting sort index    1_F_MARIA,{
    freeloop true;
    .@total = 1000;
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@array[.@i] = .@print$[.@i] = rand(50);
//  dispbottom implode( .@print$, "," );
    .@start = gettimetick(0);
    callfunc "counting_sort_index", .@array, .@output, .@total;
//  callfunc "counting_sort_index_", .@array, .@output, .@total;
    .@end = gettimetick(0);
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@print$[.@i] = .@array[ .@output[.@i] ];
//  dispbottom implode( .@print$, "," );
    dispbottom "time used -> "+( .@end - .@start )+" mili-seconds";
    end;
}
 
function    script  counting_sort_index {
    .@total = .@size = getarg( 2, getarraysize( getarg(0) ) );
    copyarray .@arr, getarg(0), .@size;
    while ( .@i < .@size )
        setd ".@index_"+ .@arr[.@i] +"["+( .@tmp[.@arr[.@i]]++ )+"]", .@i++;
    do {
        .@index = getarraysize(.@tmp) -1;
        .@out[--.@size] = getd( ".@index_"+ .@index +"["+( --.@tmp[.@index] )+"]" );
    } while( .@size );
    copyarray getarg(1), .@out, .@total;
    return;
}
 
function    script  counting_sort_index_    {
    .@total = .@size = getarg( 2, getarraysize( getarg(0) ) );
    copyarray .@arr, getarg(0), .@size;
    while ( .@i < .@size ) {
        setd ".@index_"+ .@arr[.@i] +"["+( .@tmp[.@arr[.@i]] )+"]", .@i;
        .@tmp[.@arr[.@i]]++;
        .@i++;
    }
    do {
        .@index = getarraysize(.@tmp) -1;
        .@tmp[.@index]--;
        .@out[.@size-1] = getd( ".@index_"+ .@index +"["+( .@tmp[.@index] )+"]" );
        .@size--;
    } while( .@size );
    copyarray getarg(1), .@out, .@total;
    return;
}
Viewed 1493 times, submitted by AnnieRuru.