元组作为 ets table 的键?

Tuple as Key for ets table?

我想在 ETS table 中存储有关其他网络参与者信息的元组。 我想使用 {ip_address(), port_number()} (return of inet:peername(Socket) 的元组作为条目的键。也就是我想使用地址/端口的组合作为其他节点的标识符/ ETS 中的条目 table.

ets 可以吗?还是我必须使用其他类型作为密钥?

ETS 代表 "Erlang Term Storage",它可以存储任何 Erlang 术语,包括元组和元组的元组。 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 的描述部分很重要。

对于存储的元组的哪一部分是键,没有混淆; ets:new/2 function,用于创建 table,包括 {keypos, Pos} 选项以指示关键元素。如果未提供 {keypos, Pos},则第一个元素是键。