II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
150 ¢. A. R. HOARE<br />
and has infinite cardinality, The required type is therefore declared as<br />
sparse:<br />
type carfile = sparse array owner of carset.<br />
In a data processing applicati<strong>on</strong>, a variable of carfile type would be known<br />
as a random access file, and the owner would be known as the key element of<br />
the file.<br />
The next two examples are drawn from numerical applicati<strong>on</strong>s. A vector<br />
is a mapping from integers <strong>on</strong>to floating point numbers. A sparse vector is<br />
<strong>on</strong>e in which most of the elements are zero; c<strong>on</strong>sequently its initial value will<br />
be the zero c<strong>on</strong>stant functi<strong>on</strong>, and all elements will remain zero unless an<br />
explicit assignment is made of a different value:<br />
type sparsevector = sparse array integer of real.<br />
A sparse complex matrix may be defined in a similar way"<br />
type irregular matrix = sparse array (row, column" integer)<br />
of complex.<br />
The next example is taken from the field of the translati<strong>on</strong> of programming<br />
languages to machine code. During the process of translati<strong>on</strong>, the translator<br />
needs to know certain informati<strong>on</strong> about each identifier declared in the<br />
program, such as machine address allocated to the variable, its length and<br />
type, etc. This informati<strong>on</strong> is assumed to bel<strong>on</strong>g to a type decode. The type of<br />
an array which associates a decode with each identifier is given the name<br />
dicti<strong>on</strong>ary and is declared:<br />
type dicti<strong>on</strong>ary = sparse array ident of decode<br />
Of course, the translator is interested in the decode <strong>on</strong>ly of those identifiers<br />
actually declared in the source program. For the vast majority of possible<br />
identifiers, the value given by any dicti<strong>on</strong>ary of this type will be that value of<br />
the decode type which indicates that the identifier was undeclared.<br />
The final example is of a type that causes familiar problems in a com-<br />
mercial filing system and in real life--that of multidimensi<strong>on</strong>al cross-<br />
classificati<strong>on</strong>. The customers of a firm are split up into a number of<br />
geographical areas; they are also classified in a number of classes, in accord-<br />
ance with the kind of product they purchase. On occasi<strong>on</strong>s it is required to<br />
access all customers in an area, sequencing through all classes; <strong>on</strong> other<br />
occasi<strong>on</strong>s to access all customers in a class, sequencing through the areas;<br />
and finally, it is sometimes required to process all customers of a given class<br />
in a given area. The abstract structure required to deal with this situati<strong>on</strong><br />
is a two-dimensi<strong>on</strong>al sparse array of sparse sets"<br />
sparse array (c:class; a:area) of sparse powerset customer.