Erlang ETS Table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.