## 7.10.1 Array creation and indexing

Page 218 of 800 |
| Search internet |

A Logiweb array is a data structure built up from pairs and integers which represents a function from integers to values. For an array a and an integer i, denotes the value associated to the integer i by the array a.

Arrays are 'finite' in the sense that for at most finitely many integers i. We shall refer to the set of integers for which as the *domain* of the array a. Thus, the domain of any array is a finite set of integers.

In particular, there exists one array whose domain is the empty set. We shall refer to that array as the *empty array*. As usual, the heavily overloaded value is used for representing nothingness, so it should come as no surprise that represents the empty array. Thus, we have for all integers i.

The construct returns an array which is identical to a except that the returned array maps i to v. As an example,

denotes an array which maps 1, 2, and 3 to 10, 20, and 30, respectively. As another example,

denotes an array which maps 2 and 3 to 20 and 300, respectively. The domain of the array comprises the integers 2 and 3. The integer 1 ends up being mapped to so the integer 1 is kicked out of the domain by the fourth assignment above.

Logiweb is purely functional and assigning a value to an array has no side effects. Evaluation of returns an array which maps i to v without affecting the value of a.

Note that one does not have to declare array bounds. Logiweb arrays expand and shrink as needed.

Logiweb arrays are implemented in such a way that they are efficient in most cases. In particular, they are efficient in these two cases:

- The domain consists of an interval of integers.
- The domain consists of a sparse set of randomly distributed integers.

Page 218 of 800 |
| Search logiweb.eu |

Copyright © 2010
Klaus Grue,
GRD-2010-01-05