Difference between revisions of "Pseudo Mutli-Dimensional Array (3D)"
Line 1: | Line 1: | ||
In my previous article [[Pseudo Multi-Dimensional Array]], I discussed how to acheive 2 dimensional array behavior in LSL. In this article, we will look at doing the same for a 3 dimensional array. | In my previous article [[Pseudo Multi-Dimensional Array]], I discussed how to acheive 2 dimensional array behavior in LSL. In this article, we will look at doing the same for a 3 dimensional array. | ||
<p> | |||
A list is defined as “a heterogeneous list of the other data types”. It is linear by nature and can be thought of as a single column. At the physical level, arrays are stored in contiguous sections of memory. (Another linear structure) An algorithm is used to translate between the logical rows and columns and the physical level of addresses. | |||
</p> | |||
<p> | |||
Consider a list with 48 elements. Normally we visualize this as a vertical column. In this case, it is convenient to think of them as 2 tables of 4 rows and 6 columns. Notice we are starting with element 1. Element zero is reserved for metadata about the size of the array. | |||
</p> | |||
'''Layer 0''' | |||
<table width="20%"> | |||
<tr><td> </td><td>'''0'''</td><td>'''1'''</td><td>'''2'''</td><td>'''3'''</td><td>'''4'''</td><td>'''5'''</td></tr> | |||
<tr><td>'''0'''</td><td> 1</td><td> 2</td><td> 3</td><td> 4</td><td> 5</td><td> 6</td></tr> | |||
<tr><td>'''1'''</td><td> 7</td><td> 8</td><td> 9</td><td>10</td><td>11</td><td>12</td></tr> | |||
<tr><td>'''2'''</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td></tr> | |||
<tr><td>'''3'''</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td></tr> | |||
</table> | |||
'''Layer 1''' | |||
<table width="20%"> | |||
<tr><td> </td><td>'''0'''</td><td>'''1'''</td><td>'''2'''</td><td>'''3'''</td><td>'''4'''</td><td>'''5'''</td></tr> | |||
<tr><td>'''0'''</td><td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td></tr> | |||
<tr><td>'''1'''</td><td>31</td><td>32</td><td>33</td><td>34</td><td>35</td><td>36</td></tr> | |||
<tr><td>'''2'''</td><td>37</td><td>38</td><td>39</td><td>40</td><td>41</td><td>42</td></tr> | |||
<tr><td>'''3'''</td><td>43</td><td>44</td><td>45</td><td>46</td><td>47</td><td>48</td></tr> | |||
</table> | |||
'''Figure 1.''' Indexes of a list arranged in rows and columns. |
Revision as of 15:39, 21 August 2009
In my previous article Pseudo Multi-Dimensional Array, I discussed how to acheive 2 dimensional array behavior in LSL. In this article, we will look at doing the same for a 3 dimensional array.
A list is defined as “a heterogeneous list of the other data types”. It is linear by nature and can be thought of as a single column. At the physical level, arrays are stored in contiguous sections of memory. (Another linear structure) An algorithm is used to translate between the logical rows and columns and the physical level of addresses.
Consider a list with 48 elements. Normally we visualize this as a vertical column. In this case, it is convenient to think of them as 2 tables of 4 rows and 6 columns. Notice we are starting with element 1. Element zero is reserved for metadata about the size of the array.
Layer 0
0 | 1 | 2 | 3 | 4 | 5 | |
0 | 1 | 2 | 3 | 4 | 5 | 6 |
1 | 7 | 8 | 9 | 10 | 11 | 12 |
2 | 13 | 14 | 15 | 16 | 17 | 18 |
3 | 19 | 20 | 21 | 22 | 23 | 24 |
Layer 1
0 | 1 | 2 | 3 | 4 | 5 | |
0 | 25 | 26 | 27 | 28 | 29 | 30 |
1 | 31 | 32 | 33 | 34 | 35 | 36 |
2 | 37 | 38 | 39 | 40 | 41 | 42 |
3 | 43 | 44 | 45 | 46 | 47 | 48 |
Figure 1. Indexes of a list arranged in rows and columns.