初次使用ets

 

 

一、new(Name, Options) -> tid() | atom(),创建ets表.

Options = [Option],

目测常用的属性,

{keypos, Pos}:指定key的位置,每个元组的长度必须要大约Pos,也可以使用record的字段。

named_table:ets表注册.

Type:set | ordered_set | bag | duplicate_bag:表的类型,是否允许出现重复。

Accesspublic | protected | private

 

二、查询

1.lookup(Tab, Key) -> [Object]:根据key进行查询

Types:

Tab = tab()
Key = term()
Object = tuple()

 

Returns a list of all objects with the key Key in the table Tab.

In the case of set, bag and duplicate_bag, an object is returned only if the given key matches the key of the object in the table. If the table is an ordered_set however, an object is returned if the key given compares equal to the key of an object in the table. The difference being the same as between =:= and ==. As an example, one might insert an object with the integer() 1 as a key in an ordered_set and get the object returned as a result of doing a lookup/2 with the float() 1.0 as the key to search for.

2.fun2ms(LiteralFun) -> MatchSpec.

select(Tab, MatchSpec) -> [Match]

Types:

Tab = tab()
MatchSpec = match_spec()
Match = term().

3.match(Tab, Pattern) -> [Match].

 

 

 

部分源码:

猜测:可以使用多个项元作为一个可以key,类似于复合索引
3> ets:new(my_ets,[named_table,{keypos,2},set]).
my_ets
4> ets:insert(my_ets,{1,aa,11}).                
true
5> ets:insert(my_ets,{1,{aa,11},11}).
true
6> ets:lookup(my_ets,aa).
[{1,aa,11}]
7> ets:lookup(my_ets,{aa,11}).
[{1,{aa,11},11}]

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值