[erlang-questions] How to Update List Elements A Lot

Hugo Wang w@REDACTED
Wed Jul 22 03:01:48 CEST 2015


Hi Jesper & Erik,

The updates has inner loops and not that fixed patterned. The code will
look like the following after a lot of simplicities:

void decode(char * src, char * dst, ...) {
  ...
  hash_buffer(...);  // random updates
  ... // other stuff
  has_buffer(...);
  ...
}

void hash_buffer(...) {
  ...
  shift_buffer(...);
  ...
  shift_buffer(...);
  ...
}

void shift_buffer(...) {
  ... // updating elements in dst
}


On Wed, Jul 22, 2015 at 1:16 AM, Erik Søe Sørensen <eriksoe@REDACTED>
wrote:

> Are the updates so scattered? If they are a series of front-to-back or
> back-to-front updates, then there's not much of a problem. Certain other
> fixed patterns (eg, swapping each pair of values, or in general replacing
> ..., X, Y,... with ..., f(X, Y), g(X, Y),... ) are easy too, with lists or
> binaries. The really hard case is when the sequence of indexes of the
> updates is not fixed. Purely functional data structures don't do such
> patterns too well, performance-wise - although, as has been pointed out by
> others, it may perform well enough for the purpose.
> The "ramfile" driver may be a solution,  although last time I checked it
> wasn't too fast.
> /Erik
> Den 21/07/2015 09.56 skrev "Jesper Louis Andersen" <
> jesper.louis.andersen@REDACTED>:
>
>>
>> On Tue, Jul 21, 2015 at 6:00 AM, Hugo Wang <w@REDACTED> wrote:
>>
>>> In other language, like C or Python, we can init an output list and then
>>> update its elements inline. In Erlang, what I currently do, would make a
>>> copy of the list every time when an element need to update. This looks not
>>> quite right.
>>>
>>
>> Do you have a small snippet of an inner loop somewhere? It may be easier
>> to recommend an approach then. Do note that crypto-stuff in Erlang is
>> perhaps not the best approach since the complexity of the VM makes it
>> harder to account for side channels.
>>
>>
>> --
>> J.
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150722/b68a23f0/attachment.htm>


More information about the erlang-questions mailing list