gb_trees:largest/1
返回最大的键和值
用法:
largest(Tree) -> {Key, Val}
内部实现:
-spec largest(Tree) -> {Key, Val} when
Tree :: gb_tree(),
Key :: term(),
Val :: term().
largest({_, Tree}) ->
largest_1(Tree).
largest_1({Key, Value, _Smaller, nil}) ->
{Key, Value};
largest_1({_Key, _Value, _Smaller, Larger}) ->
largest_1(Larger).
返回一个 {Key, Val} 的元组,Key 是树里最大的键,Val 是与键相关联的值(这里假设这里树不是一个空树)。
Orddict = orddict:from_list([{pear, 7}, {orange, 5}, {apple, 2}]),
Tree = gb_trees:from_orddict(Orddict),
gb_trees:largest(Tree).