Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 
Share Thread:
Reddit Facebook Twitter
Tidy recursion
05-17-2013, 12:22 PM (This post was last modified: 05-17-2013 12:57 PM by nemyax.)
Post: #1
Tidy recursion
Which is the best recursion method?
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]).
Reply


Messages In This Thread
Tidy recursion - nemyax - 05-17-2013 12:22 PM
RE: Tidy recursion - micheus - 05-18-2013, 06:22 AM
RE: Tidy recursion - nemyax - 05-19-2013, 09:14 PM
RE: Tidy recursion - dgud - 05-20-2013, 01:50 PM
RE: Tidy recursion - micheus - 05-20-2013, 01:58 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)