zoukankan      html  css  js  c++  java
  • 初次使用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}]

  • 相关阅读:
    java代码--Date类获取当前时间-格式化输出
    Eclipse快速生成do while if 等方法
    java不同包中protected修饰的属性和方法调用方法
    java中如果删除导入的jar包,工程出现叹号解决方案
    Best Reward HDU 3613(回文子串Manacher)
    Teacher YYF
    Period II
    How many
    String Problem
    Corporate Identity
  • 原文地址:https://www.cnblogs.com/ribavnu/p/3407663.html
Copyright © 2011-2022 走看看