[erlang-questions] 2D Map Arrays

Mikael Pettersson mikpe@REDACTED
Wed Sep 13 14:53:01 CEST 2006


Richard Carlsson writes:
 > Jeff Crane wrote:
 > > What do I do when I want to operate on a similarly
 > > sized dynamic layer that I want to read/write to?
 > 
 > A while ago, Dan Gudmundsson posted an array datatype implementation
 > to the list. Since then, I and Dan have been rewriting it with the
 > intention of eventually making it a standard library component. Here
 > is a preview; the interface should be pretty stable now:
 > 
 >    http://user.it.uu.se/~richardc/array/
 > 
 > It still uses a tree structure, but since it uses indices from 0 to N
 > instead of arbitrary keys, it can be quite a lot more efficient in both
 > time and space than gb_trees or dicts.

The HiPE compiler heavily uses gb_trees for array-like objects, so I
tested the array module in HiPE. The array module's interface is a close
match to our own `hipe_vectors_wrapper' module, so the integration was
easy. The array module works nicely but I haven't done any performance
measurements yet.

There are two things about the array module I don't quite like:
1. Doing a set on an index higher than the current maximum causes the
   array to grow, while doing a get on an index higher than the current
   maximum throws an exception. This makes sense for objects like partial
   mappings, but is quite strange for array-like objects. Perhaps a
   name change to "intmap" would capture its behaviour more accurately?
2. It has an extensible index range, but we only construct arrays of
   given sizes and then stay within those boundaries. So do we lose
   any performance due to the extensibility feature we don't use?

/Mikael



More information about the erlang-questions mailing list