|
|
|
|
|
by liancheng
4973 days ago
|
|
Man, are you serious when you said that "The result is that concatenating two strings takes O(1) time in Erlang, compared O(N) time in other languages"? Yes, you are right that Erlang represents strings with lists, and that's the VERY reason that Erlang must take O(N) time to concatenate two strings (N is the length of the first string). Just check your /usr/lib/erlang/lib/stdlib-xxx/src/string.erl, and you'll find this: concat(S1, S2) -> S1 ++ S2.
and "++" is obviously a O(N) operator.But yes, string concatenation is somewhat faster than other languages that represent strings with arrays of characters. Because in Erlang, it's O(N), while in others it's O(N+M), where N is the length of the first string and M is the length of the second. |
|
Maybe here you can find a bit better explanation: http://erlang.org/pipermail/erlang-questions/2012-May/066590...