gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:47:01 25 4
gpt4 key购买 nike

假设我有一个 ets 表,例如:

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

我想使用 ets:update_counter 更新元素 4

我尝试了不同的方式,但找不到解决方案,例如:

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})

我想要的结果是:

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

最佳答案

我建议仅使用一个元组作为键和值,而不是使用一个元组作为另一个元组中的值:

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"}]

关于erlang - 如何更新 ets 表中存储的元组内的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48022551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com