Arrays vs tuples / lists

Ulf Wiger (AL/EAB) <>
Mon May 17 16:09:14 CEST 2004


As long as you only look up stuff in large tuples, 
access is very fast and O(1).

Updating the tuple, however, will be expensive, as the 
whole tuple is copied.

For very large array-like structures, it's better to use
something like dict, gb_trees, or e.g. the 'lines' module
found in jungerl. They are designed to give reasonably good
performance on both read and write in large data structures.
The 'lines' module has array semantics. With dict and gb_trees,
you need to use an index as your key to get array semantics.

/Uffe

> -----Original Message-----
> From: 
> [mailto:]On Behalf Of Thomas Johnsson
> Sent: den 17 maj 2004 15:59
> To: 
> Subject: Arrays vs tuples / lists
> 
> 
> Hi,
> Erlang does not have array values as such,
> but could big tuples be used instead to get 'direct access' via
> element(N, Tuple) ?
> Or does list_to_tuple( <long list> ) give you something basically
> the same as a list in the implementation, so that element(10000,T)
> is much more expensive than element(1,T) ?
> -- Thomas Johnsson
> 



More information about the erlang-questions mailing list