• 初次使用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}]

  • 相关阅读:
    160-三个用户同时登录,是怎么实现多线程的?
    159-如何解决缓存穿透?
    158-为什么会引发缓存穿透?
    存储emoji表情,修改字符集为utf8mb4
    java相差小时数
    pom.xml解释
    前端 跨域
    java 获取的是本地的IP地址
    是否超时
    发送验证码
  • 原文地址:https://www.cnblogs.com/ribavnu/p/3407663.html
Copyright © 2020-2023  润新知