一、表遍历

通过ets:first/1获取表的第一个关键字,表中下一个关键字用ets:next/2得到,直到ets:next/2返回'$end_of_table'

当多几个进程并发访问ets表时,可以使用ets:safe_fixtable/2函数来保证,每个元素只被访问一次。

-module(traversal_ets).
-export([traversal_ets/1]).

traversal_ets(Tab) ->
    traversal_ets(Tab, ets:first(Tab), []).
traversal_ets(_,'$end_of_table',Acc) ->
    Acc;    
traversal_ets(Tab, Prv, Acc) ->
    traversal_ets(Tab, ets:next(Tab,Prv), [Prv|Acc]).

二、提取表信息,匹配match和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指定匹配输出

9> ets:match(countries,{'$1',ireland,'_'}).
[[sean],[chris]]
10> ets:match(countries,{'$1','$0',cook}).  
[[italy,marco],[france,yves]]
11> ets:match(countries,{'$2',ireland,'_'}).
[[sean],[chris]]
12> ets:match(countries,{'$2',cook,'_'}).   
[]
2、matc_object全部匹配模式元祖

13> ets:match_object(countries,{'_',ireland,'_'}).
[{sean,ireland,bartender},{chris,ireland,tester}]

3、match_delete 删除匹配输出
14> NewTab = ets:match_delete(countries,{'_',ireland,'_'}).
true

三、提取表信息筛选

ets:select

1、用匹配规约做参数

ets:select(countries,[{{'$1','$2','$3'},[{'/=','$3',cook}],[['$2','$1']]}]).

{'$1','$2','$3'} 模式

{'/=','$3',cook}保护元

['$2','$1'] 返回表达式

2、用ets:fun2ms返回匹配规约

30> MS = ets:fun2ms(fun({Name, Country,Job}) when Job /= cook ->
30> [Country,Name] end).
[{{'$1','$2','$3'},[{'/=','$3',cook}],[['$2','$1']]}]
31> ets:select(countries, MS).
[[ireland,sean],[ireland,chris]]

erlang ets表的更多相关文章

  1. Erlang ETS Table

    不需要显示用锁,插入和查询时间不仅快而且控制为常量,这就是Erlang的ETS Table. 为什么而设计? Erlang中可以用List表达集合数据,但是如果数据量特别大的话在List中访问元素就会 ...

  2. Erlang ets -- something about cache

    都说用ets 写一个cache 太简单, 那就简单的搞一个吧, 具体代码就不贴了, 就说说简要的需求和怎么做(说设计有点虚的慌). 需求场景 >> 查询系统,对于主存储而言,一次写入多次查 ...

  3. Erlang ets -- something about cache continue

    上一次说到了实现一个简单cache 的基本思路和想法, http://www.cnblogs.com/--00/p/erlang_ets_something_about_cache.html 在文末, ...

  4. erl0010 - erlang查看ets 当前系统使用情况和当前配置上限

    1.限制:erlang官网给出了ets的默认上限:“The default is 1400, can be changed with the environment variable ERL_MAX_ ...

  5. Erlang模块ets翻译

    概要: 内置的存储 描述: 这个模块是Erlang内置存储BIFs的接口.这些提供了在Erlang运行时系统中存储大量数据的能力,并且能够对数据进行持续的访问时间.(在ordered_set的情况下, ...

  6. Erlang 初学者技巧及避免的陷阱

    1. 传参或在匿名函数内慎用self() 通常在做消息传递或新建进程的时候我们需要将当前进程的Pid发给目标进程以便接收返回信息,但初学者不留意容易犯以下错误 spawn(fun() -> lo ...

  7. erlang 查看内存消耗的方法?

    找出消耗内存最多的进程 : lists:reverse(lists:keysort(2,[{P, erlang:process_info(P, heap_size)} || P <- erlan ...

  8. erlang note

    没有关于erlang interface ,继续寻找吧... --------------------------------------------------------------- erl - ...

  9. Erlang 程序引发共享内存 bug 的一个例子

    虽然 Erlang 的广告说得非常好,functional.share-nothing.消息传递,blah blah 的,好像用 Erlang 写并发程序就高枕无忧了,但是由于 Erlang 信奉高度 ...

随机推荐

  1. 在ubuntu下设置eclipse开发STM32等嵌入式设备

    之前为了能够让ROS与底层能够顺利通讯,我采用可开源开发板arduino ,因为arduino有ROS的库,能够按照ROS wiki上所给的教程就可以顺利的开发,但由于arduino的局限性,我觉得是 ...

  2. JQUERY 轮播插件

    闲来无事,写个轮播插件,项目中用到的时候就无需在写了,不然会累死宝宝的 废话少说 代码上 html部分 <div class="lunbo"> <ul> & ...

  3. Php函数完整参考手册

    序号 分类 描述 1 Array 函数 2 Calendar 函数 日历扩展包含了简化不同日历格式间的转换的函数. 3 Date/Time 函数 Date/Time 函数用于从 PHP 脚本运行的服务 ...

  4. nginx 搭建 文件下载服务

    location / { root /home/data-nginx/; index index.html index.htm; autoindex on; ##显示索引 autoindex_exac ...

  5. php 分析

    php  code in D:\10\11\php test in D:\10\11\php\test issue 1: <html><head><title>标记 ...

  6. CSS实现三角形图标的原理《转载》

    网页中经常有一种三角形的图标,鼠标点一下会弹出一个下拉菜单之类的(之前淘宝也有,不过现在改版好像没有了) 之前以为是个png图标背景,后来在bootstrap中看到有一个图标样式叫做caret的用来实 ...

  7. ubuntu14.04 下安装mysql5.6

    1.sudo apt-get install mysql-server-5.6 2.测试是否安装成功 ps aux |grep mysql mysql -u root -p 3.允许远程访问设置 su ...

  8. 非常不错的MySQL优化的8条经验

    1.选取最适用的字段属性   MySQL 可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度 ...

  9. channel bonding

    一.什么是bondingLinux bonding驱动提供了一个把多个网络接口设备捆绑为单个的网络接口设置来使用,用于网络负载均衡及网络冗余二.bonding应用方向1.网络负载均衡对于bonding ...

  10. lr_abort()、exit(-1) 和 return-1之间的区别

    int status; status = web_url("Login", "URL=https://secure.computing.com//login.asp?us ...