簡體   English   中英

如何更新存儲在 ets 表中的元組內的數字?

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

假設我有一個 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"}]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM