yeah, we're just better then awk!

Daniel Dudley <>
Tue Mar 4 21:22:24 CET 2003


"Pierpaolo BERNARDI" wrote:
[snipped]
> BTW, is there a better data structure to be used as an array
> (i.e. a map from fixed length tuples of integers)?

One way to emulate arrays is to use a keyed AVL. Tke keys
are cell index numbers (0..n), the cell contents any term.

Use integer division and the mod operator to compute row
and column 0-based indices from a given cell index. The
divisor is the number of columns. A chess board, for
example, will have 8 rows and 8 columns, both indexed
0...7. The row index of cell 28 is 28 : 8 = 3, the column
index 28 mod 8 = 4.

Conversely, computing the cell index from given row and
column indices would be row * columns + column, for example
3 * 8 + 4 = 28.

The advantage of an AVL is its super-fast access times on
individual cells. It's relatively easy to extract slices,
too (simple computations).

HTH,
Daniel



More information about the erlang-questions mailing list