erl_tree-通用二叉查找树 gb_tree
来源:互联网 发布:ubuntu 测试软件 编辑:程序博客网 时间:2024/06/09 23:10
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, 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= Treeinit()-> 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).
- erl_tree-通用二叉查找树 gb_tree
- erl_tree-avl Trees平衡二叉查找树
- 查找--二叉查找树
- 二叉树、二叉查找树
- 二叉树 & 二叉查找树
- 【查找结构】二叉查找树
- 查找之二叉树查找
- 查找之二叉树查找
- 查找:二叉查找树总结
- 二叉树查找树...
- 二叉树查找树
- 查找--遍历二叉树
- 二叉查找树
- 二叉查找树实现
- 二叉查找树
- 动态二叉查找树
- 最优二叉查找树
- 二叉查找树
- 从入门到精通:Prezi完全解读——互动出版网
- scanner
- HDU 5441 Travel (2015年长春赛区网络赛E题)
- Spring MVC上下文父子容器
- hdu 5437 Alisha’s Party 优先队列 2015 ACM/ICPC Asia Regional Changchun Online
- erl_tree-通用二叉查找树 gb_tree
- 在标题栏显示进度条progressBar
- Asynctask异步加载使用方法
- OC-字符串,数组,字典练习题
- Android 网络连接:Volley(齐射)之简单使用
- hdu 5443 The Water Problem 水题 2015 ACM/ICPC Asia Regional Changchun Online
- Mac OS X升级到10.11之后不能使用pod的问题解决方法
- 快速在任意路径中打开cmd命令提示符
- nodejs 捕获未处理异常