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}]

  • 相关阅读:
    Problem B. Harvest of Apples
    字典树的学习
    PACM Team
    2038: [2009国家集训队]小Z的袜子(hose)
    Naive Operations
    C程序设计语言练习 第三章
    数据结构C++实现-第一章 绪论
    排序
    操作系统设计与实现-第一章:序言
    进制转换
  • 原文地址:https://www.cnblogs.com/ribavnu/p/3407663.html
Copyright © 2011-2022 走看看