Page 1 of 1
Jade 2D Arrays
Posted: Fri Aug 07, 2009 12:53 pm
by ConvertFromOldNGs
by Anonymous >> Thu, 22 Sep 2005 1:10:01 GMT
Hi,
Just a quick question.
To implement 2 d arrays in jade I assume you use the Object array (Row Array) to contain the secondary array?
My question is what would be quicker.
Iterate through a collection populating a 2d string array with values to use for reporting. (Each row in the array is a row in a report (detail frame)).
Or populate a dynadictionary with the objects in collection and use that to generate the report.
Less time spent iterating through the original collection the better.
Troy
Re: Jade 2D Arrays
Posted: Fri Aug 07, 2009 12:53 pm
by ConvertFromOldNGs
by Stephen >> Thu, 22 Sep 2005 4:24:39 GMT
My personal preference :
An external key dictionary, with 2 integer keys, one for the row and one for the column.
To add your object into the "array" use myExternalDict.putAtKey(row, column, object);
To retrieve an object at a given row and column, use myExternalDict.getAtKey(row, column);
Re: Jade 2D Arrays
Posted: Fri Aug 07, 2009 12:53 pm
by ConvertFromOldNGs
by Allistar >> Sun, 25 Sep 2005 11:51:28 GMT
An alternative is to code this as a one dimensional array, and use a multiplation to access the correct object . I.e. if the 2d array needs to be 40x40, then you could have a 1600 long array. Accessing the item at [10][20] would be as simple as looking at position 200. This would probably perform better if every position in the array were to be filled. If the majority of positions were not filled then a double key dictionary would be the way to go.
Regards,
Allistar.
Re: Jade 2D Arrays
Posted: Fri Aug 07, 2009 12:53 pm
by ConvertFromOldNGs
by Troy >> Sun, 25 Sep 2005 21:18:40 GMT
Thanks very much.
Troy.
Re: Jade 2D Arrays
Posted: Fri Aug 07, 2009 12:53 pm
by ConvertFromOldNGs
by Patwos >> Mon, 26 Sep 2005 5:32:33 GMT
It sounds like you are effectively wanting to produce a "2 column" report, in which case you may be able to use the following approach:
1. Iterate the collection and create a Tab delimited string for each row of the report, storing the Tab delimited string in a 1D StringArray.
2. Now when you produce the report, you can iterate the 1D StringArray and use Table.addItem or Table.setCellText to create the rows of your report. The embedded Tabs will automatically split your row data into the 2 columns of the Table.
Of course this is somewhat simplistic as you still need to nicely handle your page breaking as appropriate and if the data for either column could itself already contain any embedded Tabs you will need to pre-process the data to replace these with something approrpiate. (eg: 4 space characters)
This technique will also work quite nicely for > 2 columns by simply adding additional Tab delimited "fields" to the 1D StringArray and additional columns to the Table control.
Hope that helps,
Pat.