ets(3)

MODULE
ets - Built-In Term Storage

DESCRIPTION

This module is an interface to the Erlang built-in term storage BIFs. These provide the ability to store very large quantities of data in an Erlang runtime system, and to have constant access time to the data. (In the case of ordered_set, see below, access time is proportional to the logarithm of the number of objects stored).

Data is organized as a set of dynamic tables, which can store tuples. Each table is created by a process. When the process terminates, the table is automatically destroyed. Every table has access rights set at creation.

Tables are divided into four different types, set, ordered_set, bag and duplicate_bag. A set or ordered_set table can only have one object associated with each key. A bag or duplicate_bag can have many objects associated with each key.

The number of tables stored at one Erlang node is limited. The current default limit is approximately 1400 tables. The upper limit can be increased by setting the environment variable ERL_MAX_ETS_TABLES before starting the Erlang runtime system (i.e. with the -env option to erl/werl). The actual limit may be slightly higher than the one specified, but never lower.

Note that there is no automatic garbage collection for tables. Even if there are no references to a table from any process, it will not automatically be destroyed unless the owner process terminates. It can be destroyed explicitly by using delete/1.

Some implementation details:

    *   In the current implementation, every object insert and look-up operation results in one copy of the object.

    *   This module provides very limited support for concurrent updates. No locking is available, but the safe_fixtable/2 function can be used to guarantee that a sequence of first/1 and next/2 calls will traverse the table without errors even if another process (or the same process) simultaneously deletes or inserts objects in the table.

    *   '$end_of_table' should not be used as a key since this atom is used to mark the end of the table when using first/next.

In general, the functions below will exit with reason badarg if any argument is of the wrong format, or if the table identifier is invalid.
 The type tid() is used to denote a table identifier. Note that the internal structure of this type is implementation-specific.

EXPORTS

all() -> [Tab]

    Types
        Tab = tid() | atom()

    Returns a list of all tables at the node. Named tables are given by their names, unnamed tables are given by their table identifiers.

delete(Tab) -> true

    Types
        Tab = tid() | atom()

    Deletes the entire table Tab.

delete(Tab, Key) -> true

    Types
        Tab = tid() | atom()
        Key = term()

    Deletes all objects with the key Key from the table Tab.

delete_all_objects(Tab) -> true

    Types
        Tab = tid() | atom()

    Delete all objects in the ETS table Tab. The deletion is atomic.

delete_object(Tab,Object) -> true

    Types
        Tab = tid() | atom()
        Object = tuple()

    Delete the exact object Object from the ETS table, leaving objects with the same key but other differences (useful for type bag).

file2tab(Filename) -> {ok,Tab} | {error,Reason}

    Types
        Filename = string() | atom()
        Tab = tid() | atom()
        Reason = term()

    Reads a file produced by tab2file/2 and creates the corresponding table Tab.

first(Tab) -> Key | '$end_of_table'

    Types
        Tab = tid() | atom()
        Key = term()

    Returns the first key Key in the table Tab. If the table is of the ordered_set type, the first key in Erlang term order will be returned. If the table is of any other type, the first key according to the table's internal order will be returned. If the table is empty, '$end_of_table' will be returned.

    Use next/2 to find subsequent keys in the table.

fixtable(Tab, true|false) -> true | false

    Types
        Tab = tid() | atom()

  Warning:

The function is retained for backwards compatibility only. Use safe_fixtable/2 instead.

Fixes a table for safe traversal. The function is primarily used by the Mnesia DBMS to implement functions which allow write operations in a table, although the table is in the process of being copied to disk or to another node. It does not keep track of when and how tables are fixed.

foldl(Function, Acc0, Tab) -> Acc1

    Types
        Function = fun(A, AccIn) -> AccOut
        Tab = tid() | atom()
        Acc0 = Acc1 = AccIn = AccOut = term()

    Acc0 is returned if the table is empty. This function is similar to lists:foldl/3. The order in which the elements of the table are traversed is unspecified, except for tables of type ordered_set, for which they are traversed first to last. Since safe_fixtable/2 is called, the table must be public or owned by the calling process.

foldr(Function, Acc0, Tab) -> Acc1

    Types
        Function = fun(A, AccIn) -> AccOut
        Tab = tid() | atom()
        Acc0 = Acc1 = AccIn = AccOut = term()

    Acc0 is returned if the table is empty. This function is similar to lists:foldr/3. The order in which the elements of the table are traversed is unspecified, except for tables of type ordered_set, for which they are traversed last to first. Since safe_fixtable/2 is called, the table must be public or owned by the calling process.

from_dets(Tab, DetsTab) -> Tab

    Types
        Tab = tid() | atom()
        DetsTab = atom()

    Fills an already created ETS table with the objects in the already opened DETS table named DetsTab. The ETS table is emptied before the objects are inserted.

fun2ms(LiteralFun) -> MatchSpec

    Types
        LiteralFun = fun() literal
        MatchSpec = term()

    Pseudo function that by means of a parse_transform translates the literal fun() typed as parameter in the function call to a match specification as described in the match_spec manual of ERTS users guide. (with literal I mean that the fun() needs to textually be written as the parameter of the function, it cannot be held in a variable which in turn is passed to the function).

    The parse transform is implemented in the module ms_transform and the source must include the file ms_transform.hrl in stdlib for this pseudo function to work. Failing to include the hrl file in the source will result in a runtime error, not a compile time dito. The include file is easiest included by adding the line -include_lib("stdlib/include/ms_transform.hrl"). to the source file.

    The fun() is very restricted, it can take only a single parameter (the object to match), a sole variable or a tuple. It needs to use the is_XXX guard tests and one cannot use language constructs that have no representation in a match_spec (like if, case, recieve etc). The return value from the fun will be the return value of the resulting match_spec.

    Example:
    2> ets:fun2ms(fun({M,N}) when N > 3 -> M end).
    [{{'$1','$2'},[{'>','$2',3}],['$1']}]

    Variables from the environment can be imported, so that this works:
    2> X=3.
    3
    3> ets:fun2ms(fun({M,N}) when N > X -> M end).
    [{{'$1','$2'},[{'>','$2',{const,3}}],['$1']}]

    The imported variables will be replaced by match_spec const expressions, which is consistent with the static scoping for erlang fun()'s. Local or global function calls can not be in the guard or body of the fun however. Calls to builtin match_spec functions of course is allowed:
    4> ets:fun2ms(fun({M,N}) when N > X, is_atomm(M) -> M end).
    Error: fun containing local erlang function calls
    ('is_atomm' called in guard) cannot be translated into match_spec
    {error,transform_error}
    5> ets:fun2ms(fun({M,N}) when N > X, is_atom(M) -> M end).
    [{{'$1','$2'},[{'>','$2',{const,3}},{is_atom,'$1'}],['$1']}]

    As you can see by the example, the function can be called from the shell too. The fun() needs to be literally in the call when used from the shell as well. Other means than the parse_transform are used in the shell case, but more or less the same restrictions apply (the exception beeing records, as they are not handled by the shell).

  Warning:

If the parse_transform is not applied to a module which calls this pseudo function, the call will fail in runtime (with a badarg). The module ets actually exports a function with this name, but it should never relly be called except for when using the function in the shell. If the parse_transform is properly applied by including the ms_transform.hrl header file, compiled code will never call the function, but the function call is replaced by a literal match_spec.

More information is provided by the ms_transform manual page in stdlib.

i() -> void()

    Displays information about all ETS tables on tty.

i(Tab) -> void()

    Types
        Tab = tid() | atom()

    Browses the table Tab on tty.

info(Tab) -> [{Item,Value}] | undefined

    Types
        Tab = tid() | atom()
        Item, Value - see below

    Returns information about the table Tab as a list of {Item, Value} tuples:

        *   Item=memory, Value=int()
             The number of words allocated to the table.

        *   Item=owner, Value=pid()
             The pid of the owner of the table.

        *   Item=name, Value=atom()
             The name of the table.

        *   Item=size, Value=int()
             The number of objects inserted in the table.

        *   Item=node, Value=atom()
             The node where the table is stored. This field is no longer meaningful as tables cannot be accessed from other nodes.

        *   Item=named_table, Value=true|false
             Indicates if the table is named or not.

        *   Item=type, Value=set|ordered_set|bag|duplicate_bag
             The table type.

        *   Item=keypos, Value=int()
             The key position.

        *   Item=protection, Value=public|protected|private
             The table access rights.

info(Tab, Item) -> Value | undefined

    Types
        Tab = tid() | atom()
        Item, Value - see below

    Returns the information associated with Item for the table Tab. In addition to the {Item, Value} pairs defined for info/1, the following items are allowed:

        *   Item=fixed, Value=true|false
             Indicates if the table is fixed by any process or not.

        *   Item=safe_fixed, Value={FirstFixed, Info}|false

            If the table has been fixed using safe_fixtable/2, the call returns a tuple where FirstFixed is the time when the table was first fixed by a process, which may or may not be one of the processes it is fixed by right now.

            Info is a possibly empty lists of tuples {Pid, RefCount}, one tuple for every process the table is fixed by right now. RefCount is the value of the reference counter, keeping track of how many times the table has been fixed by the process.

            If the table never has been fixed, the call returns false.

init_table(Name, InitFun) -> true

    Types
        Name = atom()
        InitFun = fun(Arg) -> Res
        Arg = read | close
        Res = end_of_input | {[object()], InitFun} | term()

    Replaces the existing objects of the table Tab with objects created by calling the input function InitFun, see below. This function is provided for compatibility with the DETS module, it's not more efficient than filling a table by using ets:insert/2.

    When called with the argument read the function InitFun is assumed to return end_of_input when there is no more input, or {Objects, Fun}, where Objects is a list of objects and Fun is a new input function. Any other value Value is returned as an error {error, {init_fun, Value}}. Each input function will be called exactly once, and should an error occur, the last function is called with the argument close, the reply of which is ignored.

    If the type of the table is set and there is more than one object with a given key, one of the objects is chosen. This is not necessarily the last object with the given key in the sequence of objects returned by the input functions. This holds also for duplicated objects stored in tables of type duplicate_bag.

insert(Tab, ObjectOrObjects) -> true

    Types
        Tab = tid() | atom()
        ObjectOrObjects = tuple() | [tuple()]

    Inserts the object or all of the objects in the list ObjectOrObjects into the table Tab. If there already exists an object with the same key as one of the objects, and the table is a set or ordered_set table, the old object will be replaced. If the list contains more than one object with the same key and the table is a set/ordered_set, one will be inserted, which one is not defined.

last(Tab) -> Key | '$end_of_table'

    Types
        Tab = tid() | atom()
        Key = term()

    Returns the last key Key according to Erlang term order in the table Tab of the ordered_set type. If the table is of any other type, the function is synonymous to first/2. If the table is empty, '$end_of_table' is returned.

    Use prev/2 to find preceding keys in the table.

lookup(Tab, Key) -> [Object]

    Types
        Tab = tid() | atom()
        Key = term()
        Object = tuple()

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

    If the table is of type set or ordered_set, the function returns either the empty list or a list with one element, as there cannot be more than one object with the same key. If the table is of type bag or duplicate_bag, the function returns a list of arbitrary length.

    Note that the time order of object insertions is preserved; The first object inserted with the given key will be first in the resulting list, and so on.

    Insert and look-up times in tables of type set, bag and duplicate_bag are constant, regardless of the size of the table. For the ordered_set data-type, time is proportional to the (binary) logarithm of the number of objects.

lookup_element(Tab, Key, Pos) -> Elem

    Types
        Tab = tid() | atom()
        Key = term()
        Pos = int()
        Elem = term() | [term()]

    If the table Tab is of type set or ordered_set, the function returns the Pos:th element of the object with the key Key.

    If the table is of type bag or duplicate_bag, the functions returns a list with the Pos:th element of every object with the key Key.

    If no object with the key Key exists, the function will exit with reason badarg.

match(Tab, Pattern) -> [Match]

    Types
        Tab = tid() | atom()
        Pattern = tuple()
        Match = [term()]

    Matches the objects in the table Tab against the pattern Pattern.

    A pattern is a term that may contain:

        *   bound parts (Erlang terms),

        *   '_' which matches any Erlang term, and

        *   pattern variables: '$N' where N=0,1,...

    The function returns a list with one element for each matching object, where each element is an ordered list of pattern variable bindings. An example:
    >ets:match(T, '$1').
     % Matches every object in the table
    [{rufsen,dog,7},{brunte,horse,5},{ludde,dog,5}]
    >ets:match(T, {'_',dog,'$1'}).
    [[7],[5]]
    >ets:match(T, {'_',cow,'$1'}).
    []

    If the key is specified in the pattern, the match is very efficient. If the key is not specified, i.e. if it is a variable or an underscore, the entire table must be searched. The search time can be substantial if the table is very large.

    On tables of the ordered_set type, the result is in the same order as in a first/next traversal.

match(Tab, Pattern, Limit) -> {[Match],Continuation} | '$end_of_table'

    Types
        Tab = tid() | atom()
        Pattern = tuple()
        Match = [term()]
        Continuation = term()

    Works like ets:match/2 but only returns a limited (Limit) number of matching objects. The Continuation term can then be used in subsequent calls to ets:match/1 to get the next chunk of matching objects. This is a space efficient way to work on objects in a table which is still faster than traversing the table object by object using ets:first/1 and ets:next/1.

    '$end_of_table' is returned if the table is empty.

match(Continuation) -> {[Match],Continuation} | '$end_of_table'

    Types
        Match = [term()]
        Continuation = term()

    Continues a match started with ets:match/3. The next chunk of the size given in the initial ets:match/3 call is returned together with a new Continuation that can be used in subsequent calls to this function.

    '$end_of_table' is returned when there are no more objects in the table.

match_delete(Tab, Pattern) -> true

    Types
        Tab = tid() | atom()
        Pattern = tuple()

    Deletes all objects which match the pattern Pattern from the table Tab. See match/2 for a description of patterns.

match_object(Tab, Pattern) -> [Object]

    Types
        Tab = tid() | atom()
        Pattern = Object = tuple()

    Matches the objects in the table Tab against the pattern Pattern. See match/2 for a description of patterns. The function returns a list of all objects which match the pattern.

    If the key is specified in the pattern, the match is very efficient. If the key is not specified, i.e. if it is a variable or an underscore, the entire table must be searched. The search time can be substantial if the table is very large.

    On tables of the ordered_set type, the result is in the same order as in a first/next traversal.

match_object(Tab, Pattern, Limit) -> {[Match],Continuation} | '$end_of_table'

    Types
        Tab = tid() | atom()
        Pattern = tuple()
        Match = [term()]
        Continuation = term()

    Works like ets:match_object/2 but only returns a limited (Limit) number of matching objects. The Continuation term can then be used in subsequent calls to ets:match_object/1 to get the next chunk of matching objects. This is a space efficient way to work on objects in a table which is still faster than traversing the table object by object using ets:first/1 and ets:next/1.

    '$end_of_table' is returned if the table is empty.

match_object(Continuation) -> {[Match],Continuation} | '$end_of_table'

    Types
        Match = [term()]
        Continuation = term()

    Continues a match started with ets:match_object/3. The next chunk of the size given in the initial ets:match_object/3 call is returned together with a new Continuation that can be used in subsequent calls to this function.

    '$end_of_table' is returned when there are no more objects in the table.

member(Tab, Key) -> true | false

    Types
        Tab = tid() | atom()
        Key = term()

    Works like lookup/2, but does not return the objects. The function returns true if one or more elements in the table has the key Key, false otherwise.

new(Name, Options) -> tid()

    Types
        Name = atom()
        Options = [Option]
         Option = Type | Access | named_table | {keypos, Pos}
          Type = set | ordered_set | bag | duplicate_bag
          Access = public | protected | private
          Pos = int()

    Creates a new table and returns a table identifier which can be used in subsequent operations. The table identifier can be sent to other processes so that a table can be shared between different processes within a node.

    The parameter Options is a list of atoms which specifies table type, access rights, key position and if the table is named or not. If one or more options are left out, the default values are used. This means that not specifying any options ([]) is the same as specifying [set, protected, {keypos, 1}].

        *   set The table is a set table - one key, one object, no order among objects. This is the default table type.

        *   ordered_set The table is a ordered_set table - one key, one object, ordered in Erlang term order, which is the order implied by the < and > operators. Tables of this type have a somewhat different behavior in some situations than tables of the other types.

        *   bag The table is a bag table which can have many objects, but only one instance of each object, per key.

        *   duplicate_bag The table is a duplicate_bag table which can have many objects, including multiple copies of the same object, per key.

        *   public Any process may read or write to the table.

        *   protected The owner process can read and write to the table. Other processes can only read the table. This is the default setting for the access rights.

        *   private Only the owner process can read or write to the table.

        *   named_table If this option is present, the name Name is associated with the table identifier. The name can then be used instead of the table identifier in subsequent operations.

        *   {keypos, Pos} Specfies which element in the stored tuples should be used as key. By default, it is the first element, i.e. Pos=1. However, this is not always appropriate. In particular, we do not want the first element to be the key if we want to store Erlang records in a table.

            Note that any tuple stored in the table must have at least Pos number of elements.

next(Tab, Key1) -> Key2 | '$end_of_table'

    Types
        Tab = tid() | atom()
        Key1 = Key2 = term()

    Returns the next key Key2, following the key Key1 in the table Tab. If the table is of the ordered_set type, the next key in Erlang term order is returned. If the table is of any other type, the next key according to the table's internal order is returned. If there is no next key, '$end_of_table' is returned.

    Use first/1 to find the first key in the table.

    Unless a table of type set, bag or duplicate_bag is protected using safe_fixtable/2, see below, a traversal may fail if concurrent updates are made to the table. If the table is of type ordered_set, the function returns the next key in order, even if the object does no longer exist.

prev(Tab, Key1) -> Key2 | '$end_of_table'

    Types
        Tab = tid() | atom()
        Key1 = Key2 = term()

    Returns the previous key Key2, preceding the key Key1 according the Erlang term order in the table Tab of the ordered_set type. If the table is of any other type, the function is synonymous to next/2. If there is no previous key, '$end_of_table' is returned.

    Use last/1 to find the last key in the table.

rename(Tab, Name) -> Name

    Types
        Tab = Name = atom()

    Renames the named table Tab to the new name Name. Afterwards, the old name can not be used to access the table. Renaming an unnamed table has no effect.

safe_fixtable(Tab, true|false) -> true | false

    Types
        Tab = tid() | atom()

    Fixes a table of the set, bag or duplicate_bag table type for safe traversal.

    A process fixes a table by calling safe_fixtable(Tab, true). The table remains fixed until the process releases it by calling safe_fixtable(Tab, false), or until the process terminates.

    If several processes fix a table, the table will remain fixed until all processes have released it (or terminated). A reference counter is kept on a per process basis, and N consecutive fixes requires N releases to actually release the table.

    When a table is fixed, a sequence of first/1 and next/2 calls are guaranteed to succeed even if objects are removed during the traversal. An example:
    clean_all_with_value(Tab,X) ->
      safe_fixtable(Tab,true),
      clean_all_with_value(Tab,X,ets:first(Tab)),
      safe_fixtable(Tab,false).

    clean_all_with_value(Tab,X,'$end_of_table') ->
      true;
    clean_all_with_value(Tab,X,Key) ->
      case ets:lookup(Tab,Key) of
        [{Key,X}] ->
           ets:delete(Tab,Key);
        _ ->
           true
      end,
      clean_all_with_value(Tab,X,ets:next(Tab,Key)).

    Note that no deleted objects are actually removed from a fixed table until it has been released. If a process fixes a table but never releases it, the memory used by the deleted objects will never be freed. The performance of operations on the table will also degrade significantly.

    Use info/2 to retrieve information about which processes have fixed which tables. A system with a lot of processes fixing tables may need a monitor which sends alarms when tables have been fixed for too long.

    Note that for tables of the ordered_set type, safe_fixtable/2 is not necessary as calls to first/1 and next/2 will always succeed.

select(Tab, MatchSpec) -> [Object]

    Types
        Tab = tid() | atom()
        Object = tuple()
        MatchSpec = term()

    Matches the objects in the table Tab using a match_spec as described in ERTS users guide. This is a more general call than the ets:match/2 and ets:match_object/2 calls. In its simplest forms the match_spec's look like this:

        *   MatchSpec = [MatchFunction]

        *   MatchFunction = {MatchHead, [Guard], [Result]}

        *   MatchHead = "Pattern as in ets:match"

        *   Guard = {"Guardtest name", ...}

        *   Result = "Term construct"

    This means that the match_spec is always a list of one or more tuples (of arity 3). The tuples first element should be a pattern as destcribed in the documentation of ets:match/2. The second element of the tuple should be a list of 0 or more guard tests (described below). The third element of the tuple should be a list containing a description of the value to actually return. In almost all normal cases the list contains exactly one term which fully describes the value to return for each object.

    The return value is constructed using the "match variables" bound in the MatchHead or using the special match variables '$_' (the whole matching object) and '$$' (all match variables in a list), so that the following <c>ets:match/2 expression:
                ets:match(Tab,{'$1','$2','$3'})

    is exactly equivalent to:
                ets:select(Tab,[{{'$1','$2','$3'},[],['$$']}])

    - and the following ets:match_object/2 call:
                ets:match_object(Tab,{'$1','$2','$1'})

    is exactly equivalent to
                ets:select(Tab,[{{'$1','$2','$1'},[],['$_']}])

    Composite terms can be constructed in the Result part either by simply writing a list, so that this code:
                ets:select(Tab,[{{'$1','$2','$3'},[],['$$']}])

    gives the same output as:
                ets:select(Tab,[{{'$1','$2','$3'},[],[['$1','$2','$3']]}])

    i.e. all the bound variables in the match head as a list. If tuples are to be constructed, one has to write a tuple of arity 1 with the single element in the tuple beeing the tuple one wants to construct (as an ordinary tuple could be mistaken for a Guard). Therefore the following call:
                ets:select(Tab,[{{'$1','$2','$1'},[],['$_']}])

    gives the same output as:
                ets:select(Tab,[{{'$1','$2','$1'},[],[{{'$1','$2','$3'}}]}])

    - this syntax is equivalent to the syntax used in the trace patterns (see the dbg module in the runtime_tools application).

    The Guard's are constructed as tuples where the first element is the name of the test (again, see the match_spec documentation in ERTS users guide) and the rest of the elements are the parameters of the test. To check for a specific type (say a list) of the element bound to the match variable '$1', one would write the test as {is_list, '$1'}. If the test fails, the object in the table won't match and the next MatchFunction (if any) will be tried. Most guard tests present in erlang can be used, but only the new versions prefixed is_ are allowed (like is_float, is_atom etc). An exact list of the allowed guard tests is present in the match_spec section of ERTS users guide.

    The Guard section can also contain logic and arithmetic operations, which are written with the same syntax as the guard tests (prefix notation), so that a guard test written in erlang looking like this:
                is_integer(X), is_integer(Y), X + Y < 4711

    is expressed like this (X replaced with '$1' and Y with '$2'):
                [{is_integer, '$1'}, {is_integer, '$2'}, {'<', {'+', '$1',
                '$2'}, 4711}]

    A complete list of the operators is present in the match_spec section of ERTS users guide.

select(Tab, MatchSpec, Limit) -> {[Match],Continuation} | '$end_of_table'

    Types
        Tab = tid() | atom()
        Object = tuple()
        MatchSpec = term()
        Continuation = term()

    Works like ets:select/2 but only returns a limited (Limit) number of matching objects. The Continuation term can then be used in subsequent calls to ets:select/1 to get the next chunk of matching objects. This is a space efficient way to work on objects in a table which is still faster than traversing the table object by object using ets:first/1 and ets:next/1.

    '$end_of_table' is returned if the table is empty.

select(Continuation) -> {[Match],Continuation} | '$end_of_table'

    Types
        Match = [term()]
        Continuation = term()

    Continues a match started with ets:select/3. The next chunk of the size given in the initial ets:select/3 call is returned together with a new Continuation that can be used in subsequent calls to this function.

    '$end_of_table' is returned when there are no more objects in the table.

select_delete(Tab, MatchSpec) -> NumDeleted

    Types
        Tab = tid() | atom()
        Object = tuple()
        MatchSpec = term()
        NumDeleted = integer()

    Matches the objects in the table Tab using a match_spec as described in ERTS users guide. If the match_spec returns the atom true for an object, that object is removed from the table. For any other result from the match_spec the object is retained. This is a more general call than the ets:match_delete/2 call.

    The function returns the number of objects actually deleted from the table.

select_count(Tab, MatchSpec) -> NumMatched

    Types
        Tab = tid() | atom()
        Object = tuple()
        MatchSpec = term()
        NumMatched = integer()

    Matches the objects in the table Tab using a match_spec as described in ERTS users guide. If the match_spec returns the atom true for an object, that object considered a match and is counted. For any other result from the match_spec the object is not considered a match and is therefore not counted.

    The function could be described as a match_delete/2 that does not actually delete any elements, but only counts them.

    The function returns the number of objects matched.

slot(Tab, I) -> [Object] | '$end_of_table'

    Types
        Tab = tid() | atom()
        I = int()
        Object = tuple()

  Warning:

The function is deprecated and may be removed from future releases. Use first/next or last/prev instead.

Returns all objects in the I:th slot of the table Tab. A table can be traversed by repeatedly calling the function, starting with the first slot I=0 and ending when '$end_of_table' is returned. The function will fail with reason badarg if the I argument is out of range.

Unless a table of type set, bag or duplicate_bag is protected using safe_fixtable/2, see above, a traversal may fail if concurrent updates are made to the table. If the table is of type ordered_set, the function returns a list containing the I:th object in Erlang term order.

tab2file(Tab, Filename) -> ok | {error,Reason}

    Types
        Tab = tid() | atom()
        Filename = string() | atom()
        Reason = term()

    Dumps the table Tab to the file Filename. The implementation of this function is not efficient.

tab2list(Tab) -> [Object]

    Types
        Tab = tid() | atom()
        Object = tuple()

    Returns a list of all objects in the table Tab.

test_ms(Tuple, MatchSpec) -> {ok, Result} | {error, Errors}

    Types
        Tuple = tuple()
        MatchSpec = term()
        Result = term()
        Errors = [{warning|error, string()}]

    This function is a utility to test the match_spec's used in calls to ets:select/2. The function both tests the MatchSpec for "syntactic" correctness and runs the match_spec against the object Tuple. If the match_spec contains errors, the tuple {error, Errors} is returned where Errors is a list of natural language descriptions of what was wrong with the match_spec. If the match_spec is syntactically OK, the function returns {ok, Term} where Term is what would have been the result in a real ets:select/2 call or false if the match_spec does not match the object Tuple.

    This is a useful debugging and test tool, especially when writing complicated ets:select/2 calls.

to_dets(Tab, DetsTab) -> Tab

    Types
        Tab = tid() | atom()
        DetsTab = atom()

    Fills an already created/opened DETS table with the objects in the already opened ETS table named Tab. The DETS table is emptied before the objects are inserted.

update_counter(Tab, Key, {Pos,Incr}) -> Result
update_counter(Tab, Key, Incr) -> Result

    Types
        Tab = tid() | atom()
        Key = term()
        Pos = Incr = Result = int()

    This functions provides an efficient way to update a counter, without the hassle of having to look up an object, update the object by incrementing an element and insert the resulting object into the table again.

    It will destructively update the object with key Key in the table Tab by adding Incr to the element at the Pos:th position. The new counter value is returned. If no position is specified, the element directly following the key (<keypos>+1) is updated.

    The function will fail with reason badarg if:

        *   the table is not of type set or ordered_set,

        *   no object with the right key exists,

        *   the object has the wrong arity, or,

        *   the element to update is not an integer.

AUTHOR
 Claes Wikstrom, Tony Rogvall, Patrik Nyblom - support@erlang.ericsson.se