3 ms·
I just had a thought; if arguments always get cloned by value every time they are passed to a function, doesn't that mean that the time complexity for an insert
by jondubois 10y ago
I just had a thought; if arguments always get cloned by value every time they are passed to a function, doesn't that mean that the time complexity for an insertion operation in Elixir can never be better than O(n)?
According to this answer http://stackoverflow.com/questions/11055391/time-complexity-of-erlang-dict http://stackoverflow.com/questions/11055391/time-complexity-... it claims that for dictionaries it's O(log n). How is that possible if mutations are not allowed? Wouldn't the function have to process at least n items? Or it uses parallel processing to get a speedup there?
- andy_ppp 10y agoIf I create an immutable string "hello world" why would it be passed by copy; it can never be changed only garbage collected. The BEAM seems to do magic here and do much less work than you might think when creating "new" things.
- owaislone 10y agoIf you are only dealing with Immutable structures that no one can really change, there is no point in passing by value. You can always pass by reference. The language will not allow any code to modify it. Instead a new variable will have to be assigned if the function changes the values. So, it can always be pass by reference until a change needs to be made aka copy on write.