Sparse arrays - The HAC Language
Description: The HAC Language

Next: Array size-equivalence, Previous: Dense arrays, Up: Arrays

### 4.2 Sparse arrays

A sparse array, on the other hand, is a generalization of a (possibly multidimensional) set, whose indices need not be continuous.

One feature of HAC is that one may arbitrarily extend arrays, as sets of indices, with multiple declarations. A dense array can be made sparse by adding indexed instances that break the dense condition.

This example declare collection `q` with two statements, resulting in a sparsely poplulated (sparse) collection.

Sparse array from declarations:

         int q[2][2][2];
         int q[1][1][3..3];   // result is sparse

A sparse array can be populated densely by filling in indices to satisfy the dense condition,

Dense array from declarations:

         pint q[1..1][0..1][2..3];
         pint q[1][1][2..3];
         pint q[1][1..1][2..3]; // result is dense

The only constraint is that one cannot re-instantiate an index that has been previously instantiated.