Skip to content

Instantly share code, notes, and snippets.

@suncle1993
Created November 30, 2017 05:41
Show Gist options
  • Save suncle1993/d2cffd7afcd26a82645c651e71d5b353 to your computer and use it in GitHub Desktop.
Save suncle1993/d2cffd7afcd26a82645c651e71d5b353 to your computer and use it in GitHub Desktop.
Erlang dets的使用:增删查遍历
Eshell V7.3 (abort with ^G)
1> dets:open_file(bbb, [{type, bag}]).
{ok,bbb}
2> dets:lookup(bbb, "b11").
[{"b11","b22","b32"},{"b11","b21","b31"}]
3>
3> dets:lookup(bbb, "a11").
[]
4>
4> dets:insert(bbb, {"b11", "b23", "b33"}).
ok
5> dets:lookup(bbb, "b11").
[{"b11","b22","b32"},
{"b11","b21","b31"},
{"b11","b23","b33"}]
6> detes:delete_object(bbb, {"b11","b22","b32"}).
** exception error: undefined function detes:delete_object/2
7> dets:lookup(bbb, "b11").
** exception error: bad argument
in function dets:lookup/2
called as dets:lookup(bbb,"b11")
8> f().
ok
9> dets:open_file(bbb, [{type, bag}]).
{ok,bbb}
10> dets:lookup(bbb, "b11").
[{"b11","b22","b32"},
{"b11","b21","b31"},
{"b11","b23","b33"}]
11> dets:delete_object(bbb, {"b11","b22","b32"}).
ok
12> dets:lookup(bbb, "b11").
[{"b11","b21","b31"},{"b11","b23","b33"}]
13> dets:traverse(bbb, )
13>
13>
13> .
* 1: syntax error before: ')'
13> dets:lookup(bbb, "b11").
[{"b11","b21","b31"},{"b11","b23","b33"}]
14> dets:traverse(bbb,
14> fun({A, B, C}) ->
14> dets:delete_object(bbb, {A, B, C}), continue end).
[]
15> dets:lookup(bbb, "b11").
[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment