viewing paste topic/4321- comb sort haru | Athena

Posted on the
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
prontera,152,188,5  script  annie comb_sort 100,{
    .@total = 1000; 
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@array[.@i] = rand(10000);
    .@start = gettimetick(0);
    freeloop 1;
    callfunc "comb_sort_annie", .@array, .@output, .@total;
    .@end = gettimetick(0);
    for ( .@i = 0; .@i < .@total; .@i++ )
        dispbottom .@array[ .@output[.@i] ] +"";
    dispbottom "time used -> "+( .@end - .@start )+" mili-seconds"; // 468-514 miliseconds
    end;
}
 
prontera,155,188,5  script  haru comb_sort  100,{
    .@total = 1000; 
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@array[.@i] = rand(10000);
    .@start = gettimetick(0);
    freeloop 1;
    callfunc "comb_sort_haru", .@array, .@output, .@total;
    .@end = gettimetick(0);
    for ( .@i = 0; .@i < .@total; .@i++ )
        dispbottom .@array[ .@output[.@i] ] +"";
    dispbottom "time used -> "+( .@end - .@start )+" mili-seconds"; // 483-500 miliseconds
    end;
}
 
prontera,158,188,5  script  getitemname2 ID sorted  100,{
    freeloop 1;
    getinventorylist;
    dispbottom "Comb sort === Total items : "+ @inventorylist_count +" ===";
    callfunc "comb_sort_haru", @inventorylist_id, .@output, @inventorylist_count;
    .@i = 0;
    while ( .@i < @inventorylist_count ) {
        .@itemname$ = callfunc("getitemname2", @inventorylist_id[ .@output[.@i] ], @inventorylist_identify[ .@output[.@i] ], @inventorylist_refine[ .@output[.@i] ], @inventorylist_attribute[ .@output[.@i] ], @inventorylist_card1[ .@output[.@i] ], @inventorylist_card2[ .@output[.@i] ], @inventorylist_card3[ .@output[.@i] ], @inventorylist_card4[ .@output[.@i] ]);
        dispbottom "("+ @inventorylist_id[ .@output[.@i] ] +") "+ .@itemname$ +": "+ @inventorylist_amount[ .@output[.@i] ] +" ea.";
        .@i++;
    }
    end;
}
 
//  callfunc "comb_sort", <input array>, <output index>, <total index>;
function    script  comb_sort_annie {
    while ( .@i < getarg(2) ) {
        set .@arr[.@i], getelementofarray( getarg(0), .@i );
        set getelementofarray( getarg(1), .@i ), .@i; // note : I'm generating a dummy index here, so this one will be output as the sorted index later
        .@i++;
    }
    .@size = .@gap = getarg(2);
    do {
        if ( .@gap > 1 )
            .@gap = .@gap * 10 / 13;
        .@i = .@swap = 0;
        while ( .@i + .@gap < .@size ) {
            if ( .@arr[.@i] > .@arr[ .@i + .@gap ] ) {
                .@tmp = .@arr[.@i];
                .@arr[.@i] = .@arr[ .@i + .@gap ];
                .@arr[ .@i + .@gap ] = .@tmp;
                .@tmp = getelementofarray( getarg(1), .@i ); // dummy index is being swap here
                set getelementofarray( getarg(1), .@i ), getelementofarray( getarg(1), .@i + .@gap );
                set getelementofarray( getarg(1), .@i + .@gap ), .@tmp;
                .@swap = 1;
            }
            .@i++;
        }
    } while ( .@swap || .@gap > 1 );
    return;
}
 
//  callfunc "comb_sort", <input array>, <output index>, <total index>;
function    script  comb_sort_haru  {
    .@size = .@gap = getarg(2);
    copyarray .@arr, getarg(0), .@size;
    while ( .@i < .@size ) {
        set getelementofarray( getarg(1), .@i ), .@i;
        .@i++;
    }
    .@gap10 = .@size * 10;
    do {
        if ( .@gap10 > 10 ) {
            .@gap10 = .@gap10 * 10 / 13;
            .@gap = .@gap10 / 10;
        }
        .@i = .@swap = 0;
        while ( .@i + .@gap < .@size ) {
            if ( .@arr[.@i] > .@arr[ .@i + .@gap ] ) {
                .@tmp = .@arr[.@i];
                .@arr[.@i] = .@arr[ .@i + .@gap ];
                .@arr[ .@i + .@gap ] = .@tmp;
                .@tmp = getelementofarray( getarg(1), .@i );
                set getelementofarray( getarg(1), .@i ), getelementofarray( getarg(1), .@i + .@gap );
                set getelementofarray( getarg(1), .@i + .@gap ), .@tmp;
                .@swap = 1;
            }
            .@i++;
        }
    } while ( .@swap || .@gap10 > 10 );
    return;
}
Viewed 1259 times, submitted by AnnieRuru.