One, table traversal
Get the first keyword of the table by ETS:FIRST/1, and the next keyword in the table is ETS:NEXT/2 until ETS:NEXT/2 returns ' $end _of_table '
When more than one process accesses the ETS table concurrently, you can use the ETS:SAFE_FIXTABLE/2 function to ensure that each element is accessed only once.
Ii. extracting table information, matching match and Match_object
24> ets:new (countries, [bag,named_table]).
Countries
25> Ets:insert (Countries,{yves,france,cook}).
True
26> Ets:insert (Countries,{marcoitaly,cook}).
True
27> Ets:insert (Countries,{sean,ireland,bartender}).
True
28> Ets:insert (Countries,{chris,ireland,tester}).
True
1. Match specifies matching output
9> Ets:match (countries,{' $ ', Ireland, ' _ '}).
[[Sean],[chris]]
10> Ets:match (countries,{' $ ', ' $ A ', cook}).
[[Italy,marco],[france,yves]]
11> Ets:match (countries,{' $ ", Ireland, ' _ '}).
[[Sean],[chris]]
12> Ets:match (countries,{' $ ", cook, ' _ '}).
[]
2, matc_object all matching mode Yuan zu
13> Ets:match_object (countries,{' _ ', Ireland, ' _ '}).
[{Sean,ireland,bartender},{chris,ireland,tester}]
3. Match_delete Delete Matching output
14> NewTab = Ets:match_delete (countries,{' _ ', Ireland, ' _ '}).
True
Third, the extraction table information filtering
Ets:select
1, with matching specifications to do parameters
Ets:select (countries,[{{' $ ', ' $ $ ', ' $ $ '},[{'/= ', ' $ $ ', cook}],[[' $ $ ', ' $ ']}]).
{' $ ', ' $ $ ', ' $ $ '} mode
{'/= ', ' $ $ ', cook} protector
[' $ $ ', ' $ '] returns an expression
2. Return the matching protocol with ets:fun2ms
30> MS = ets:fun2ms ({Name, country,job}) when Job/= Cook-
30> [Country,name] end).
[{' $ ', ' $ ', ' $ '},[{'/= ', ' $ $ ', ' $ ' cook}],[[', ' $ ']}]
31> ets:select (countries, MS).
[[Ireland,sean],[ireland,chris]]
Erlang ETS Table