Oct 26 2015 | 3:34 am

Hi all, I have a dict which has the (simplified) hierarchy shown at the bottom of this post.
I have a number of groups, each of which contain a number of items, each of which have the same fields. It's like a mega simple database.
The data is very small (less than 5 groups, less than 5 items per group) but very dynamic (nearly all fields updating 30fps, occasionally new items added or removed).

What i'd like to do is:
* find the items which have a specific field set to 1 (e.g. data4 == 1)
* sort those items according to a specific field (e.g. data3[0])
* iterate this sorted subset of items in order to do other things.

I have no idea where to begin!

I have a really ghetto idea which is:
* iterate the dict and check each item if its data4 == 1
* if it is, concatenate the value I'd like to sort on (e.g. data3[0]) with the full path of the item, and add to an array (i.e. this array would be [5.2_group1::item2 3.45_group2::item1 7.3454_group2::item3]
* sort the array with zl.sort
* split each item in the array using '_' as a divider and lose the first part
* I now have an array which is the full path of each item, sorted [group2::item1 group1::item2 group2::item3]

I haven't implemented this yet, because it feels so horrible. Is there a better way?

I can't put this in a matrix because the data is all different lengths and types, and even contains strings and other stuff.

I was thinking perhaps I should go sqllite, but I'm worried about performance. I'm filling pretty much nearly all of the fields of this dict every frame at 30fps. Would that work with sqllite?

//sample data structure:
group1:
___item1 :
______data1: [value value]
______data2: [value value value]
______data3: value
______data4: 0
___item2 :
______data1: [value value]
______data2: [value value value]
______data3: value
______data4: 1
group2:
___item1 :
______data1: [value value]
______data2: [value value value]
______data3: value
______data4: 1
___item2 :
______data1: [value value]
______data2: [value value value]
______data3: value
______data4: 0
___item3 :
______data1: [value value]
______data2: [value value value]
______data3: value
______data4: 1

// this is what I'd like to add to the dict:
sorted : [group2::item1 group1::item2 group2::item3]

cheers