简体   繁体   中英

Tuple as Key for ets table?

I want to store tuples regarding information on other network participants in an ETS table. I would like to use a tuple of {ip_address(), port_number()} (return of inet:peername(Socket) as the key of the entries. Aka I want to use the combination of address / port as an identifier for the other nodes / entries in the ETS table.

Is this possible with ets? Or do I have to use an other type as a key?

ETS stands for "Erlang Term Storage" and it can store any Erlang term, including tuples and tuples of tuples. The description section of the ets man page details how terms are compared and matched for particular table types, and the documentation for ets:lookup/2 discusses this as well. For some table types, Erlang term order is important.

There is no confusion regarding which part of a stored tuple is the key; the ets:new/2 function , used to create a table, includes the {keypos, Pos} option to indicate the key element. If {keypos, Pos} is not provided, the first element is the key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM