gb_trees:get/2
在树里查找一个键(如果存在的话)
用法:
get(Key, Tree) -> Val
内部实现:
%% This is a specialized version of 'lookup'. -spec get(Key, Tree) -> Val when Key :: term(), Tree :: gb_tree(), Val :: term(). get(Key, {_, T}) -> get_1(Key, T). get_1(Key, {Key1, _, Smaller, _}) when Key get_1(Key, Smaller); get_1(Key, {Key1, _, _, Bigger}) when Key > Key1 -> get_1(Key, Bigger); get_1(_, {_, Value, _, _}) -> Value.
获取保存在树里的跟键 Key 相关的值。这里假设树里是存在这个键,否则将报错。
Tree1 = gb_trees:empty(), Tree2 = gb_trees:enter(a, 1, Tree1), gb_trees:get(a, Tree2).