gb_trees:to_list/1
把一个树转为一个列表
用法:
to_list(Tree) -> [{Key, Val}]
内部实现:
-spec to_list(Tree) -> [{Key, Val}] when
Tree :: gb_tree(),
Key :: term(),
Val :: term().
to_list({_, T}) ->
to_list(T, []).
to_list_1(T) -> to_list(T, []).
to_list({Key, Value, Small, Big}, L) ->
to_list(Small, [{Key, Value} | to_list(Big, L)]);
to_list(nil, L) -> L.
把一个树 Tree 转为一个 key-value 的元组形式的列表。
Orddict = orddict:from_list([{pear, 7}, {orange, 5}, {apple, 2}]),
Tree = gb_trees:from_orddict(Orddict),
gb_trees:to_list(Tree).