Skip to content

@arhibot /gist:1343341
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
-module(t).
-compile(export_all).
merge([], NewTree)->
NewTree;
merge([{Node, Ch}|Tail], NewTree) ->
case lists:member(Node, NewTree) of
true -> merge(Tail, NewTree);
false -> merge(Tail, [{Node, Ch}|NewTree])
end.
add_to_tree_iter(Tree, _, [], NewTree) ->
merge(Tree, NewTree);
add_to_tree_iter(Tree, Parent, [Child| Childs], NewTree) ->
case proplists:get_value(Parent, Tree) of
undefined -> add_to_tree_iter(Tree, Child, Childs, [{Parent, [Child]}|NewTree]);
HChilds when is_list(HChilds) ->
NChilds = case lists:member(Child, HChilds) of
false -> [Child|HChilds];
true -> HChilds
end,
add_to_tree_iter(Tree, Child, Childs, [{Parent, NChilds}|NewTree])
end.
add_to_tree(Tree, [From| Childs]) ->
add_to_tree_iter(Tree, From, Childs, []).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.