简体   繁体   English

如何更新存储在 ets 表中的元组内的数字?

[英]How to update a number inside a tuple stored in an ets table?

Suppose I have an ets table like:假设我有一个 ets 表,如:

I = ets:new(mytable, [named_table, set]).
ets:insert(I, {10,{10, 4 ,"description"}).

I would like to update the element 4 using the ets:update_counter .我想使用ets:update_counter更新元素4

I tried in different way, but can't find the solution, for example:我尝试了不同的方法,但找不到解决方案,例如:

ets:update_counter(I, 10 , {3,1}).

** exception error: bad argument
     in function  ets:update_counter/3
        called as ets:update_counter(mytable,10,{3,1})

I'd like to have the result as:我希望结果如下:

{10,{10, 5 ,"description"}

I recommend to use just one tuple for key and values, instead of using a tuple for values in another tuple:我建议只对键和值使用一个元组,而不是对另一个元组中的值使用元组:

1> I = ets:new(mytable, [named_table, set]).
mytable
2> ets:insert(I, {10, 10, 4 ,"description"}).
true
3> ets:update_counter(I, 10 , {3,1}).        
5
4> ets:lookup(I, 10).
[{10,10,5,"description"}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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