Erlang常用関数
7510 ワード
1、消重アルゴリズム:
?
1
2
3
4
2、並べ替えアルゴリズム:
?
1
2
要素に基づいてソート
?
1
2
3
4
5
6
7
8
9
10
11
3、並べ替え+消重アルゴリズム:
?
1
2
4、
?
1
2
3
4
?
1
2
3
4
1
> List = [
1
,
2
,
3
,
1
,
2
,
4
].
[
1
,
2
,
3
,
1
,
2
,
4
]
2
> sets
:to_list
(sets
:from_list
(List)).
[
3
,
2
,
1
,
4
]
2、並べ替えアルゴリズム:
?
1
2
3
>lists
:sort
(List).
[
1
,
1
,
2
,
2
,
3
,
4
]
要素に基づいてソート
?
1
2
3
4
5
6
7
8
9
10
11
4
>rd(app{id,date,pkg_name,appname,version,user_num,new_user_num,used_num,los,sum_user}).
app
5
> Sort = fun (
A
,
B
)->
A
#app.date =< B#app.date end.
#Fun<erl_eval.12.113037538>
6
> lists
:sort
(Sort,
D
).% date
[
#app{
id = {app_id,{
2010
,
7
,
1
},<<
"Packagename"
>>},
date = {
2010
,
7
,
1
},
pkg_name = <<
"Packagename"
>>,appname = <<
"Appname"
>>,
version = <<
"Version"
>>,user_num =
1
,new_user_num =
1
,
used_num =
1
,los =
7223
,sum_user =
2
}... ...
3、並べ替え+消重アルゴリズム:
?
1
2
7
> ordsets
:from_list
(List).
[
1
,
2
,
3
,
4
]
4、
?
1
2
3
4
foldl(Fun(Elem, AccIn), Acc0, List) -> Acc1 %%AccIn Acc0, Elem List , List
lists
:foldl
(fun(Key, Acc) ->[proplists
:get_value
(Key, Options) | Acc]
end
, [], lists
:reverse
([pool_id, hostname, port, username,password,database, logfun, encoding, poolsize]))
: Options=
"[{hostname,"
localhost
"}, {username, "
root
"}, {password,"
sa
"}, {database, "
test
"}]"
[undefine,
"localhost"
, undefine,
"root"
,
"sa"
,
"test"
, undefine, undefine, undefine]