ETS named_table

new(Name, Options) -> tid() | atom()

  • Name = atom()
  • Options  = [Option]
  •  Option = Type | Access | named_table |  {keypos,Pos} | {heir,pid(),HeirData} | {heir,none} |  {write_concurrency,bool()}
  •   Type = set |  ordered_set | bag | duplicate_bag
  •   Access =  public | protected | private
  •   Pos = int()
  •   HeirData = term()
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},{heir,none},{write_concurrency,false}].
  • 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. Most notably the ordered_set tables regard keys as equal when they compare equal, not only when they match. This means that to an ordered_set, the integer() 1 and the float() 1.0 are regarded as equal. This also means that the key used to lookup an element not necessarily matches the key in the elements returned, if float()'s and integer()'s are mixed in keys of a table.
  • 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.
  • {heir,Pid,HeirData}  | {heir,none}
    Set a process as heir. The heir will inherit the table if the owner terminates. The message {'ETS-TRANSFER',tid(),FromPid,HeirData} will be sent to the heir when that happens. The heir must be a local process. Default heir is none, which will destroy the table when the owner terminates.
  • {write_concurrency,bool()} Performance tuning. Default is false, which means that the table is optimized towards concurrent read access. An operation that mutates (writes to) the table will obtain exclusive access, blocking any concurrent access of the same table until finished. If set to true, the table is optimized towards concurrent write access. Different objects of the same table can be mutated (and read) by concurrent processes. This is achieved to some degree at the expense of single access and concurrent reader performance. Note that this option does not change any guarantees about atomicy and isolation. Functions that makes such promises over several objects (like insert/2) will gain less (or nothing) from this option.
    Table type ordered_set is not affected by this option in current implementation.