contentsconceptssyntaxlibrariessampleserrorsindex
Full text search
Arrays: multi-dimensional
    Related Syntax  

Key-based indexing can be used to simulate multi-dimensional arrays.

One example of a two-dimensional array is a table. Each item in the table has a row and a column. Shelf item keys could contain the row number and the column number separated by some separator character like a period ".". Alternatively, if each row and column has a "name", then those names could be used in the keys instead of the row and column numbers. The following code is an example of a two-dimensional array, with the shelf item keys composed of the row number and column number for each item, separated by a period:

  down-translate

  global counter row
  global counter col
  global stream table variable

  element table
     clear table
     set row to 0
     suppress

  element row
     increment row
     set col to 0
     suppress

  element col
     increment col
     set table ^ "%d(row).%d(col)" to "%c"

An example of a three-dimensional array with which most readers will be familiar can be found with Rubik's Cube. Suppose we are using OmniMark to solve the cube. The cube is made up of 26 sub-cubes (the centre, where you would expect to find the 27th, is empty and thus doesn't need to take up an item on our shelf). Each sub-cube is given a three-part key. The first part indicates where it is relative to the table: 1 if it's in the top layer, 2 if it's in the middle layer, and 3 if it's in the bottom layer. The second part of the key indicates if the sub-cube is in the left slice of the cube (1), the middle slice (2), or the right slice (3). Finally, the third part is used to tell if the sub-cube is facing us (1), in the middle (2), or facing away from us (3).

So, the top-left-front sub-cube would be indicated with a key of "1.1.1" and the bottom-right-rear sub-cube by "3.3.3". Note that there would be no item with a key of "2.2.2" because that is the empty position. An arbitrary position given by three counters, x, y, and z, could be specified by the key %d(x) . %d(y) . %d(z).

How this shelf would actually be used to solve Rubik's Cube is left as an exercise to the interested reader.

      Related Syntax
   %d
   key
 
----

Top [CONTENTS] [CONCEPTS] [SYNTAX] [LIBRARIES] [SAMPLES] [ERRORS] [INDEX]

Generated: April 21, 1999 at 2:00:46 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-1999.