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