erl_tree-通用二叉查找树 gb_tree
2015-09-14 12:13
387 查看
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
%% 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。。
在坚强:/article/4598618.html 博客里有对各个函数的相应分析,
以下是对部分函数的关注点分析:
insert 函数 插入不是每次都balance :
insert_1(Key, Value, nil, S) when S =:= 0 ->
{{Key, Value, nil, nil}, 1, 1};
….
if
H > P ->
balance(T, SS);
gb_trees balance 是重构树,先to_list_1(T) 然后递归二分构造。
在后面一章中我们会分析avl_tree 的balance LL\RR\LR\RL 操作
以下是对gb_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。。
在坚强:/article/4598618.html 博客里有对各个函数的相应分析,
以下是对部分函数的关注点分析:
insert 函数 插入不是每次都balance :
insert_1(Key, Value, nil, S) when S =:= 0 ->
{{Key, Value, nil, nil}, 1, 1};
….
if
H > P ->
balance(T, SS);
gb_trees balance 是重构树,先to_list_1(T) 然后递归二分构造。
在后面一章中我们会分析avl_tree 的balance LL\RR\LR\RL 操作
以下是对gb_trees 的一些封装:
%%=========General Balanced Trees============== %% gb_trees={Size,Tree} %% Tree= {Key, Value, Smaller, Bigger} |nil %% Smaller=Tree %% Bigger= Tree init()-> gb_trees:empty(). insert(Key, Val, Tree1)-> gb_trees:insert(Key, Val, Tree1). lookup(Key, Tree)-> gb_trees:lookup(Key, Tree). get(Key, Tree)-> gb_trees:get(Key, Tree). balance(Tree1) -> gb_trees:balance(Tree1). delete(Key, Tree1)-> gb_trees:delete(Key, Tree1).
相关文章推荐
- UITabBarControler解决旋转问题
- 查找问题的方法与思路
- scanner
- hdu 5437 Alisha’s Party 优先队列 2015 ACM/ICPC Asia Regional Changchun Online
- asp 中文乱码问题解决方法
- sql语句中----删除表数据drop、truncate和delete的用法
- MyBatis-Spring-SqlSessionFactoryBean
- BOTC软件开发模型思想之核心代码区分——php示例001
- 关键路径法里的总浮动时间和自由浮动时间的对比及分析
- [CareerCup] 8.9 An In-memory File System 内存文件系统
- iOS中nil,Nil,NULL之间的区别
- shell脚本实现对网卡流量监控
- HDU 5441 Travel (2015ACM/iCPC长春网络赛E )
- hdu 5441 Travel 并查集 2015 ACM/ICPC Asia Regional Changchun Online
- 递归求最小公倍数
- 如何解决Oracle 11g EM网站报“此网站的安全证书存在问题”
- ApplicationContext
- 包装类与数据类型之间的转换
- SSL ENGINE机制 二
- AM-资产冻结与停用