GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2015-07-09 23:53:16

iFredQC
Member
Registered: 2015-06-05
Posts: 6

ds_list_sort_array

This script is used to sort multiple ds_lists together in the same way ds_grids work.

array = An array of ds_lists
index = Which ds_list from the array should the sort be based on
ascending = If true, data will be sorted in ascending order

Expand///ds_list_sort_array(array,index,ascending)
var l = array_length_1d(argument0);
var s = ds_list_size(argument0[0]);
var g = ds_grid_create(l, s);
for(var a = 0; a < l; a += 1) {
    for(var b = 0; b < s; b += 1) {
        g[#a, b] = ds_list_find_value(argument0[a], b);
    }
}
ds_grid_sort(g, argument1, argument2);
for(a = 0; a < l; a += 1) {
    for(b = 0; b < s; b += 1) {
        ds_list_replace(argument0[a], b, g[#a, b]);
    }
}
ds_grid_destroy(g);

Optimization could be done by finding a faster way to copy data between a grid and a list.

Offline

#2 2015-07-10 10:40:05

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: ds_list_sort_array

This is nice way to do this sort of operation. I feel like there may be another script that does something like this but this is probably the better way to go.

I don't think the data transcription could be sped up in any worthwhile way. There are some underhanded tricks you can do with data structure read/write functions to reorganize data but I don't know that they would be applicable or wise. When natively compiled, this should be very fast. A boost may be possible by taking advantage of low-level caching but I've not looked into it yet.

Thanks for the submission.


Abusing forum power since 1986.

Offline

#3 2015-08-05 14:36:35

iFredQC
Member
Registered: 2015-06-05
Posts: 6

Re: ds_list_sort_array

I just had an idea. I can't confirm that it will work right now, but if we "write" the data using ds_list/grid_write and compare the two, we could find the differences and just do some string manipulation to quickly copy from one to the other. The data is most likely exported in the same way, it's probably just the headers and separators that change.

Offline

Board footer

Powered by FluxBB