gb_tree :(General Balanced Trees) 通用二叉查找树,通常被用作有序字典.
gb_trees={Size,Tree}
Tree= {Key, Value, Smaller, Bigger} |nil
Smaller=Tree
Bigger= Tree
整个结构都是用key 来判断节点位置,gb_tree对key有这样一段注释:
%% The term order is an arithmetic total order, so we should not
%% test exact equality for the keys. (If we do, then it becomes
%% possible that neither >',
<’, nor `=:=’ matches.) Testing ‘<’
%% and ‘>’ first is statistically better than testing for
%% equality, and also allows us to skip the test completely in the
%% remaining case.
在我的测试中key可以是term int string。。
在坚强:http://www.cnblogs.com/me-sa/archive/2012/06/23/erlang-gb_trees.html 博客里有对各个函数的相应分析,
以下是对部分函数的关注点分析:
insert 函数 插入不是每次都balance :
insert_1(Key