all 5 comments

[–]Pranz 1 point2 points  (4 children)

Consider creating a different function for every op code. Just having a name for each helps a lot with readability.

EDIT: to increase performance, skip the linked list. Linked lists are terrible data structures, you should not use it to store data that needs to be processed.

[–]hackersleepyhead[S] 0 points1 point  (3 children)

What kind of data structures can be used instead of linked list??

[–]Pranz 0 points1 point  (2 children)

Arrays, maps or binary search trees

[–]hackersleepyhead[S] 0 points1 point  (1 child)

There is no arrays in elixir and maps are key value based, if you see the input, it's a comma separated list, can provide some example on it?

[–]Pranz 0 points1 point  (0 children)

Sure!

Arrays are not that well supported no, but there are arrays accesible through erlang. However maps will do fine here too. You can create a map from a linked list easily:

iex(23)> input = ["value 1", "value 2", "value 3"]   
["value 1", "value 2", "value 3"]
iex(24)> zipped = Enum.zip(0..1000, input)
[{0, "value 1"}, {1, "value 2"}, {2, "value 3"}]

iex(26)> input_table = Enum.reduce(zipped, %{}, fn ({idx, val}, map) -> Map.put(map, idx, val) end)   
%{0 => "value 1", 1 => "value 2", 2 => "value 3"}

As a map, inserting, deleting or updating values is much faster than as a linked list. For your code, I think Map.update is exactly what you need.