Page 1 of 1

Array with nested items?

Posted: Fri Mar 12, 2010 6:26 am
by heyvern
Stuck again.

I am reading in a file format that has "layers" and can have layers with in layers. Nested layers. Only certain types of layers can be nested and I have the ability to check for that during my repeat when reading in the layers.
Layers are enclosed with "{ }" brackets.

I have a great function that iterates and keeps track of nested layers and converting to XML and maintaining the nesting for display purposes in a field. I am also placing the layers inside an array by counting the number of layers and indexing, but... having trouble figuring out how to handle nested layers inside the array.

As you can see below there can be any number of sub layers nested very very deep. No limit to the nesting. I need a way to store that info in the array so I can retrieve it later for writing the file back out to either XML or to the original file format. I already have the file converted perfectly to XML with nested layers and it works great. However I found the array handling much easier to code for processing and only use the XML for display purposes in a field. One of the problems is that the XML is WAY to big to include all the data so I have to put in only the top level items and break it into smaller chunks or it chokes RR and crashes.

There are 4 "layer types" that are groups. When processing the layer data I "know" what the layer type is so I can trap that info. I just don't know the best way to store this data. The layer portions of the file format is 90% of the data. It can be HUGE so I need to avoid using any line counting for repeat loops.

To make things "easier" sub layers of group layers ALWAYS follow the group layer and are indented with tabs. Each set of sub layers is indented with extra tabs.

Code: Select all

{
Layer 1 --group type layer
lots and lots of text for each layer inside brackets
   {
   sub Layer 1
   sub layer of Layer 1
   }
   {
   sub Layer 2 -- sub layer of Layer 1 -- also a group type layer
      {
      sub Layer 1-- sub layer of sub Layer 2
      }
      {
      sub Layer 2 -- sub layer of sub Layer 2
      }
   }
}
{
Layer 2
lots and lots of text for each layer inside brackets
}
{
Layer 3
lots and lots of text for each layer inside brackets
}
Below is how I am constructing the array for the layers. I need unique ID's to access layer content. I count each layer and put it in a numbered array. However this solution doesn't include the nesting.

Code: Select all

layers[1 ]-- this is a group layer and includes any number of following layers "inside" it.
layers[2] -- sub layer of Layer 1
layers[3] -- this is a sub layer of Layer 1 and also has sub layers
layers[4] -- this is a sub layer of Layer 3 which is a sub layer of Layer 1 above it.
layers[5] -- this is a sub layer of the above layer which is a sub layer of the layer above it.
...
Basically I am trying to figure out a way to index layers in an array that has some way to determine sub layers. But I also need a unique ID attribute that can be passed to a function to display that layer's content in another XML display field.

Re: Array with nested items?

Posted: Fri Mar 12, 2010 5:03 pm
by BvG
There's two way, the classic way, and the multi dimensional array way.

Classic would be to add a itemdelimited list. There's math stuff for that cases, for example matrixMultiply or transpose. similar to this:

array[1,4,6] -- the sixth subitem of the fourth subitem of the first toplevel item


Another way is to use multidimensional arrays:

array[1][4][6] --same as above, so to say

Re: Array with nested items?

Posted: Fri Mar 12, 2010 9:53 pm
by heyvern
Thanks for the info.

The trouble I'm having is how to check for the parent levels and sub levels doing a "repeat for each line" loop. I can figure out how to tag each layer but can't figure out how to determine if a layer is inside a group or the parent of a group for inclusion in the array or delimited list.