Which is the best recursion method?
I like the first one, but does it introduce too much overhead?
1)
2)
3)
I like the first one, but does it introduce too much overhead?
1)
Code:
get_indices(<<>>) ->
[];
get_indices(Bin) ->
{<<I:16/unsigned-little-integer>>,NewBin} = split_binary(Bin, 2),
[I|get_indices(NewBin)].
2)
Code:
get_indices(<<>>) ->
[];
get_indices(Bin) ->
{<<I:16/unsigned-little-integer>>,NewBin} = split_binary(Bin, 2),
[I] ++ get_indices(NewBin).
3)
Code:
get_indices(Bin) ->
get_indices(Bin, []).
get_indices(<<>>, Result) ->
lists:reverse(Result);
get_indices(Bin, Result) ->
{<<I:16/unsigned-little-integer>>,NewBin} = split_binary(Bin, 2),
get_indices(NewBin, [I|Result]).