• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D Programming v
« Previous 1 2 3 4
Tidy recursion

 
  • 0 Vote(s) - 0 Average
Tidy recursion

nemyax
Offline

Member

Posts: 128
Threads: 14
Joined: Nov 2012
#1
05-17-2013, 12:22 PM (This post was last modified: 05-17-2013, 12:57 PM by nemyax.)
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]).
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



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

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode