`

ets表

 
阅读更多
access() = public | protected | private
type() = set | ordered_set | bag | duplicate_bag

set      默认类型,一个键对应一个对象,对象之间是无序的。
ordered_set  一个键对应一个对象, key整数1和浮点数1.0是相同的。
bag         一个键可以对应多个对象,但每个对象只能对应一个键。
duplicate_bag 一个键可对应多个对象,每个对象也可以对应多个键。

protected 是默认的, 只有所属进程能写,其他进程只能读。

it will not automatically be destroyed unless the owner process terminates.
The default owner is the process that created the table. Table ownership can be transferred at process termination by using the heir option or explicitly by calling give_away/3.

All updates to single objects are guaranteed to be both atomic and isolated.


new(Name, Options) -> tid() | atom()
  Name = atom()
Options = [Option]
Option = Type
       | Access
       | named_table
       | {keypos, Pos}
       | {heir, Pid :: pid(), HeirData}
       | {heir, none}
       | Tweaks

// Creates a new table and returns a table identifier which can be used in subsequent operations.

info(Tab) -> InfoList | undefined 
// Returns information about the table Tab as a list of tuples.

delete(Tab) -> true
   // Deletes the entire table Tab.

delete_all_objects(Tab) -> true
   // Delete all objects in the ETS table Tab. The operation is guaranteed to be atomic and isolated.

delete(Tab, Key) -> true
  // Deletes all objects with the key Key from the table Tab.

insert(Tab, ObjectOrObjects) -> true
  ObjectOrObjects = tuple() | [tuple()]
  // Inserts the object or all of the objects in the list ObjectOrObjects into the table Tab. If the table is a set and the key of the inserted objects matches the key of any object in the table, the old object will be replaced.
The entire operation is guaranteed to be atomic and isolated, even when a list of objects is inserted.

insert_new(Tab, ObjectOrObjects) -> boolean()
  // 当key不存在才会插入,即不会覆盖旧项


lookup(Tab, Key) -> [Object]
  // Returns a list of all objects with the key Key in the table Tab.


first(Tab) -> Key | '$end_of_table'
  // Returns the first key Key in the table Tab.  If the table is empty, '$end_of_table' will be returned.


tab2file(Tab, Filename) -> ok | {error, Reason}
    Filename = file:name()
// Dumps the table Tab to the file Filename.

file2tab(Filename) -> {ok, Tab} | {error, Reason}
    Filename = file:name()
// Reads a file produced by tab2file/2 or tab2file/3 and creates the corresponding table Tab.


tab2list(Tab) -> [Object]
    Object = tuple()
  // Returns a list of all objects in the table Tab.


all() -> [Tab]   // Returns a list of all tables at the node.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics