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;
}