gb_trees:is_defined/2
检测键是否在树里存在
用法:
is_defined(Key, Tree) -> boolean()
内部实现:
-spec is_defined(Key, Tree) -> boolean() when Key :: term(), Tree :: gb_tree(). is_defined(Key, {_, T}) -> is_defined_1(Key, T). is_defined_1(Key, {Key1, _, Smaller, _}) when Key < Key1 -> is_defined_1(Key, Smaller); is_defined_1(Key, {Key1, _, _, Bigger}) when Key > Key1 -> is_defined_1(Key, Bigger); is_defined_1(_, {_, _, _, _}) -> true; is_defined_1(_, nil) -> false.
检测键是否在树里存在,如果存在则返回 true,否则返回 false。
Tree1 = gb_trees:empty(), Tree2 = gb_trees:enter(a, 1, Tree1), gb_trees:is_defined(a, Tree2).