- 浏览: 39097 次
- 来自: 深圳
文章分类
最新评论
-
ZacMa:
哈哈,突然感觉里面没怎么介绍,全是贴代码了
<8>redis及erl-redis阅读 -
惊涛翻案:
马博士,给我开课吧
<8>redis及erl-redis阅读
%% 对list模块经常用到的进行补充
%% 1 对所有元素进行去重
%% (1) lists:umerge
%% (2)
ldrop_dup(List) ->
Fun = fun(X, List1) ->
IsMem = lists:member(X, List1),
if IsMem == true ->
List1;
true ->
[X|List1]
end
end,
RetList = lists:foldl(Fun, [], List),
lists:reverse(RetList).
%% 去掉某个元素
ldrop_ele(Ele, List) ->
erlang:display([?MODULE, ?LINE, Ele, List]),
Fun = fun(X, List1) ->
if X == Ele ->
List1;
true ->
[X|List1]
end
end,
RetList = lists:foldl(Fun, [], List),
lists:reverse(RetList).
%% 对某个元素进行去重, 留下第一个,其他的都删除
%% 如果只有一个就删除
ldrop_one_dup(Ele, List) ->
Ret = ldrop_one_dup_i(Ele, List, 0, []),
Ret.
ldrop_one_dup_i(Ele, [], Count, RetList) ->
RList = lists:reverse(RetList),
if Count == 1 ->
ldrop_ele(Ele, RList);
true ->
RList
end;
ldrop_one_dup_i(Ele, [H|T], Count, RetList) ->
if H == Ele andalso Count == 0 ->
ldrop_one_dup_i(Ele, T, 1, [H|RetList]);
H == Ele andalso Count == 1 ->
ldrop_one_dup_i(Ele, T, 2, RetList);
H == Ele andalso Count > 1 ->
ldrop_one_dup_i(Ele, T, Count, RetList);
true ->
ldrop_one_dup_i(Ele, T, Count, [H|RetList])
end.
%% 对某个子列表的元素进行去重, 去重List1的
ldrop_list_dup([], List2) ->
List2;
ldrop_list_dup(List1, List2) ->
[H|T] = List1,
NewList = ldrop_one_dup(H, List2),
ldrop_list_dup(T, NewList).
%% 对某个子列表的元素完全去掉,去掉list1的
ldrop_list([], List2) ->
List2;
ldrop_list(List1, List2) ->
[H|T] = List1,
NewList = ldrop_ele(H, List2),
ldrop_list(T, NewList).
%% 替换,把列表的首次遇到的某个值,替换为另一个值, 把Ele1替换为Ele2
%% 如果不存在,返回原来的值
lrep_one(Ele1,Ele2, List) ->
lrep_one1(Ele1, Ele2, false, List, []).
lrep_one1(_Ele1, _Ele2, Flag, [], List) ->
if Flag ->
List;
true ->
lists:reverse(List)
end;
lrep_one1(Ele1, Ele2, Flag, List1, List2) ->
[H1|T1] = List1,
if H1 == Ele1 ->
NewList2 = [Ele2|List2],
if is_atom(T1) ->
RList = [T1|NewList2],
lists:reverse(RList);
true ->
%RList1 = lists:reverse(NewList2),
%RList = lists:merge([RList1, T1])
RList1 = lists:reverse(T1),
RList2 = lists:merge(RList1, NewList2),
RList = lists:reverse(RList2),
lrep_one1(Ele1, Ele2, true, [], RList)
end;
true ->
lrep_one1(Ele1, Ele2, Flag, T1, [H1|List2])
end.
%% 替换,把列表的某个值,完全替换为另一个值, 把Ele1替换为Ele2
lrep_all(Ele1, Ele2, List) ->
Fun = fun(X, List1) ->
if X == Ele1 ->
[Ele2 | List1];
true ->
[X|List1]
end
end,
RetList = lists:foldl(Fun, [], List),
lists:reverse(RetList).
lists.erl 模块注意事项:
(1)
append/1: 实现中用到 ++
append([E]) -> E;
append([H|T]) -> H ++ append(T);
append([]) -> [].
(2)
delete/2 实现用递归,却非尾递归
delete(Item, [Item|Rest]) -> Rest;
delete(Item, [H|Rest]) ->
[H|delete(Item, Rest)];
delete(_, []) -> [].
(3)
dropwhile/2
dropwhile(Pred, [Hd|Tail]=Rest) ->
case Pred(Hd) of
true -> dropwhile(Pred, Tail);
false -> Rest
end;
dropwhile(Pred, []) when is_function(Pred, 1) -> [].
删除函数返回true的元素,如果遇到返回false立即返回剩余的列表,不管以后是否能有返回true的元素
(4)
duplicate/2
duplicate(N, X) when is_integer(N), N >= 0 -> duplicate(N, X, []).
duplicate(0, _, L) -> L;
duplicate(N, X, L) -> duplicate(N-1, X, [X|L]).
如果不要is_integer的guard语句,当传入参数N非整形,返回bad argument in an arithmetic expression, 否则返回
no function clause matching lists:duplicate
(5)
lists里面的bif
%% Bifs: member/2, reverse/2
%% Bifs: keymember/3, keysearch/3, keyfind/3
(6)
suffix/2
suffix(List1, List2)
List1如果是List2的子列表,结尾子列表,则为true,否则false
(7)
不少的对元祖组成的列表处理,
keydelete
keyfind
keymap
keymember
keymerge
keyreplace
...
lists主要是对list的各种处理,包括各种复杂的元素结构,例如元祖组成的列表等
%% 1 对所有元素进行去重
%% (1) lists:umerge
%% (2)
ldrop_dup(List) ->
Fun = fun(X, List1) ->
IsMem = lists:member(X, List1),
if IsMem == true ->
List1;
true ->
[X|List1]
end
end,
RetList = lists:foldl(Fun, [], List),
lists:reverse(RetList).
%% 去掉某个元素
ldrop_ele(Ele, List) ->
erlang:display([?MODULE, ?LINE, Ele, List]),
Fun = fun(X, List1) ->
if X == Ele ->
List1;
true ->
[X|List1]
end
end,
RetList = lists:foldl(Fun, [], List),
lists:reverse(RetList).
%% 对某个元素进行去重, 留下第一个,其他的都删除
%% 如果只有一个就删除
ldrop_one_dup(Ele, List) ->
Ret = ldrop_one_dup_i(Ele, List, 0, []),
Ret.
ldrop_one_dup_i(Ele, [], Count, RetList) ->
RList = lists:reverse(RetList),
if Count == 1 ->
ldrop_ele(Ele, RList);
true ->
RList
end;
ldrop_one_dup_i(Ele, [H|T], Count, RetList) ->
if H == Ele andalso Count == 0 ->
ldrop_one_dup_i(Ele, T, 1, [H|RetList]);
H == Ele andalso Count == 1 ->
ldrop_one_dup_i(Ele, T, 2, RetList);
H == Ele andalso Count > 1 ->
ldrop_one_dup_i(Ele, T, Count, RetList);
true ->
ldrop_one_dup_i(Ele, T, Count, [H|RetList])
end.
%% 对某个子列表的元素进行去重, 去重List1的
ldrop_list_dup([], List2) ->
List2;
ldrop_list_dup(List1, List2) ->
[H|T] = List1,
NewList = ldrop_one_dup(H, List2),
ldrop_list_dup(T, NewList).
%% 对某个子列表的元素完全去掉,去掉list1的
ldrop_list([], List2) ->
List2;
ldrop_list(List1, List2) ->
[H|T] = List1,
NewList = ldrop_ele(H, List2),
ldrop_list(T, NewList).
%% 替换,把列表的首次遇到的某个值,替换为另一个值, 把Ele1替换为Ele2
%% 如果不存在,返回原来的值
lrep_one(Ele1,Ele2, List) ->
lrep_one1(Ele1, Ele2, false, List, []).
lrep_one1(_Ele1, _Ele2, Flag, [], List) ->
if Flag ->
List;
true ->
lists:reverse(List)
end;
lrep_one1(Ele1, Ele2, Flag, List1, List2) ->
[H1|T1] = List1,
if H1 == Ele1 ->
NewList2 = [Ele2|List2],
if is_atom(T1) ->
RList = [T1|NewList2],
lists:reverse(RList);
true ->
%RList1 = lists:reverse(NewList2),
%RList = lists:merge([RList1, T1])
RList1 = lists:reverse(T1),
RList2 = lists:merge(RList1, NewList2),
RList = lists:reverse(RList2),
lrep_one1(Ele1, Ele2, true, [], RList)
end;
true ->
lrep_one1(Ele1, Ele2, Flag, T1, [H1|List2])
end.
%% 替换,把列表的某个值,完全替换为另一个值, 把Ele1替换为Ele2
lrep_all(Ele1, Ele2, List) ->
Fun = fun(X, List1) ->
if X == Ele1 ->
[Ele2 | List1];
true ->
[X|List1]
end
end,
RetList = lists:foldl(Fun, [], List),
lists:reverse(RetList).
lists.erl 模块注意事项:
(1)
append/1: 实现中用到 ++
append([E]) -> E;
append([H|T]) -> H ++ append(T);
append([]) -> [].
(2)
delete/2 实现用递归,却非尾递归
delete(Item, [Item|Rest]) -> Rest;
delete(Item, [H|Rest]) ->
[H|delete(Item, Rest)];
delete(_, []) -> [].
(3)
dropwhile/2
dropwhile(Pred, [Hd|Tail]=Rest) ->
case Pred(Hd) of
true -> dropwhile(Pred, Tail);
false -> Rest
end;
dropwhile(Pred, []) when is_function(Pred, 1) -> [].
删除函数返回true的元素,如果遇到返回false立即返回剩余的列表,不管以后是否能有返回true的元素
(4)
duplicate/2
duplicate(N, X) when is_integer(N), N >= 0 -> duplicate(N, X, []).
duplicate(0, _, L) -> L;
duplicate(N, X, L) -> duplicate(N-1, X, [X|L]).
如果不要is_integer的guard语句,当传入参数N非整形,返回bad argument in an arithmetic expression, 否则返回
no function clause matching lists:duplicate
(5)
lists里面的bif
%% Bifs: member/2, reverse/2
%% Bifs: keymember/3, keysearch/3, keyfind/3
(6)
suffix/2
suffix(List1, List2)
List1如果是List2的子列表,结尾子列表,则为true,否则false
(7)
不少的对元祖组成的列表处理,
keydelete
keyfind
keymap
keymember
keymerge
keyreplace
...
lists主要是对list的各种处理,包括各种复杂的元素结构,例如元祖组成的列表等
发表评论
-
erlang版本安装相关问题 <32>
2014-05-10 15:54 627<1> erlang R1603安装后,crytp ... -
关于iolist<30>
2014-01-15 10:42 630iolist是比较常用的数据结构. iolist的 ... -
erlang 字符编码 <29>
2014-01-14 16:31 1264用mochiweb通过网页发送中文到服务器,结果服务器显示乱码 ... -
<27>erlang record
2013-11-19 11:19 779平时总是忘记record的某些使用方法,每次使用都要翻文档, ... -
<26>io:format io_lib:format
2013-11-14 11:07 1318使用io_lib时候要注意参数,尤其是封装json串的时候,否 ... -
<24>用error_logger间隔记录日志
2013-10-22 16:09 655执行下面的代码 test:start(). test.erl ... -
<23>erlang 数据存储
2013-10-15 22:15 1664做为后端开发者,经常 ... -
<22> erlang中的数学计算函数相关
2013-10-10 10:34 16351. 幂函数 match:pow(m,n) 表示m的n次幂 ... -
<20>erlang中的类型和函数说明
2013-09-15 11:25 984erlang是一种动态类型的语言(运行时才决定数据类型),可以 ... -
<19>erlang中的时间,日期
2013-09-06 11:21 1198时间函数涉及的数据类型: DATA TYPES datetim ... -
<18>Efficient guide 之List handling
2013-08-31 18:45 6791 Deep and flat lists lists:fl ... -
<17>Efficiency Guide之Function
2013-08-27 22:30 5811. 函数模式匹配 模式匹配,在函数头,case和receiv ... -
<16>Efficiency Guide之Common Caveats
2013-08-11 11:07 814(1) ++ 如果做一个list的反转,不要这样, naiv ... -
<15> lists模块解析和补充
2013-07-24 17:57 12%% 对list模块经常用到的进行补充 %% 1 对所有元素 ... -
<12>简述erlang的几种错误
2013-04-14 23:31 11851) badarg Bad argument. The ar ... -
<11>erlang中方便使用的模块和命令(2)
2013-04-06 22:33 802(1) 进程字典到底用不用,很多人推荐使用 http:// ... -
<9>rabbitmq网络层
2013-01-31 00:20 818抽离出了网络层, 逻辑层待以后研究 https://gith ... -
<8>redis及erl-redis阅读
2013-01-16 10:14 8551 redis的功能相当的强大,里面的发布订阅pub/su ... -
<7>pg2 分析
2012-12-08 13:42 1260网上看到erlang的pg2模块似乎没人推荐使用,但是还是有不 ... -
<6>error_logger 使用
2012-12-02 16:24 1455erlang中日志管理主要有error_loggger 模块, ...
相关推荐
Storage Structures <br> Arrays <br> Linked Lists <br> Hash Tables <br> Binary Trees <br> Red/Black Trees <br> Summary <br> <br> Chapter 12. Optimizing IO <br> Efficient Screen Output <br> Efficient ...
各种函数以及库文件的...Ended Queues <br>C++ Lists <br>C++ Priority Queues <br>C++ Queues <br>C++ Stacks <br>C++ Sets <br>C++ Multisets <br>C++ Maps <br>C++ Multimaps <br>C++ Bitsets <br>Iterators <br>
<br>Published by Prentice-Hall in 1988 <br><br>ISBN 0-13-110362-8 (paperback)<br>ISBN 0-13-110370-9 <br><br>Contents<br>Preface <br>Preface to the first edition <br>Introduction <br>Chapter 1: A ...
Lists and Pairs <br>Section 6.4. Numbers <br>Section 6.5. Characters <br>Section 6.6. Strings <br>Section 6.7. Vectors <br>Section 6.8. Symbols <br><br>Chapter 7. Input and Output <br>Section 7.1. ...
Linked lists <br>Chapter 19: Stacks <br>Chapter 20: Queues and Priority Queues <br>Chapter 21: Trees <br>Chapter 22: Heap <br>Chapter 23: File Input/Output and pmatrices <br>Appendix A: Quick ...
映射文件的模块化(Modular mapping files)<br>6. 集合类(Collections)映射<br>6.1. 持久化集合类(Persistent Collections)<br>6.2. 映射集合(Mapping a Collection)<br>6.3. 值集合和多对多关联(Collections of...
映射文件的模块化(Modular mapping files)<br>6. 集合类(Collections)映射<br>6.1. 持久化集合类(Persistent Collections)<br>6.2. 映射集合(Mapping a Collection)<br>6.3. 值集合和多对多关联(Collections of...
(2KB)<END><br>28,listfind.zip<br>This sample shows how to use the CList<> template. (9KB)<END><br>29,ndbrow.zip<br>This Visual C++ 6 project shows how to create an MDI application that hosts ...
15.zip<br>Tips: ODBC & Access database<br>ODBC和Access数据库的使用技巧(5KB)<END><br>16,16.zip<br>Using DBGrid in unbound mode<br>在unbound模式下使用DBGrid(6KB)<END><br>17,ADORsWizard.zip<br>ADO Data ...
数据结构与算法分析(Java版英文)目录<br>PartI<br>Chapter1-Overview <br>Chapter2-Arrays<br>Chapter3-Simple Sorting<br>PartII<br>Chapter4--Stacks and Queues<br>Chapter5-linked lists<br>Chapter^-Recursion...
Get the Most Out of grep<br> Section 15. Manipulate Files with sed<br> Section 16. Format Text at the Command Line<br> Section 17. Delimiter Dilemma<br> Section 18. DOS Floppy Manipulation<br> ...
List<string> listS=new List<string>(); listS.Add(str); listS.Add(hello); string[] str=listS.ToArray(); 二、数组转List (从string[]转到List<string>) string[] str={str,string,abc}; List<string> listS=...
<br><br> v.2.1(Build 2001/11/29)<br> - 修正了几个BUG.<br><br> v.2.1(Build 2001/11/22)<br> - 修正了几个BUG.<br> - 增加多语言功能.<br><br> v.2.1(Build 2001/11/15)<br> - 修正了几个BUG.<br><br> v.2.1...
<END><br>12 , telnet.zip<br>Telnet Application<END><br>13 , validip.zip<br>Validate an IP address<br>14 , dmvbtest.zip<br>This is a complete email sending client in Visual Basic<END><br>15 , ...
When you click on a table, it lists all <END><br>38,3a.zip<br>An Inventory System, you can add, edit, sort, find, delete, print, change your password and create a backup of your database<END><br>39,A...
HTML提供两种类型的列表:无序列表(unordered lists, `<ul>`)和有序列表(ordered lists, `<ol>`)。无序列表使用圆点或其他符号来分隔项目,而有序列表则使用数字或字母进行排序。每个列表项由`<li>`标签定义。...
* Home Page<br>* http://visual-mingw.sourceforge.net/<br>*<br>* Mailing list<br>* http://sourceforge.net/mail/?group_id=46778<br>* visual-mingw-general@lists.sourceforge.net<br>*<br>* License<br>* ...
```ip access-list extended {<number> | <name>} [<sequence>] {permit | deny} <protocol> <source> [<ports>] <destination> [<ports>] [<options>]``` 在这个扩展版本中,`<number>`范围为100-199(扩展列表)或...
and Open Shortest Path First(OSPF)<br>第七章:Layer 2 Switching<br>第八章:Virtual LANs(VLANs)<br>第九章:Managing a Cisco Interwork<br>第十章:Managing Traffic with Access Lists<br>第十一章:...