[erlang-questions] Should I use arrays to optimize?

Richard Evans richardprideauxevans@REDACTED
Wed Feb 29 16:38:02 CET 2012


OK thanks guys.

On Wed, Feb 29, 2012 at 3:29 PM, Richard Carlsson <
carlsson.richard@REDACTED> wrote:

> On 02/29/2012 04:20 PM, Pierpaolo Bernardi wrote:
>
>> On Wed, Feb 29, 2012 at 16:13, Richard Evans
>> <richardprideauxevans@REDACTED**com <richardprideauxevans@REDACTED>>
>>  wrote:
>>
>>> I need to store a list of records. Sometimes I need to update the nth
>>> member
>>> in that list. Each record is quite large (hundreds of bytes). I have
>>> hundreds of such records.
>>>
>>> I am currently using an erlang list and using lists:keyreplace to update
>>> the
>>> nth member in the list. But this gets slow as the list gets larger, so I
>>> want to optimize and use something which overwrites rather than copies.
>>>
>>> Should I use the array module for this? If not, what do you recommend?
>>>
>>
>> a gb-tree with keys in 1..n.
>>
>> Or a random-access list.  Not in stdlib, but several implementations
>> floating around, including one from me. Ask me if you don't find one.
>>
>
> Why? The array module is basically using the same techniques as the
> gb_trees module, except that it is optimized for keys in 0..N. (For one
> thing, it doesn't need to actually store the keys - it can compute the
> position in the tree given the key, so it uses less storage and fewer
> comparisons.) The array module also handles sparse arrays just fine, so the
> keys don't have to be a dense range.
>
>   /Richard
>
> ______________________________**_________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120229/80aa3dfe/attachment.htm>


More information about the erlang-questions mailing list