从 Nim 中的 CountTable 中删除键

Remove key from CountTable in Nim

我是不是遗漏了什么,或者在 Nim (1.0.4) 中真的不可能从 CountTable 中删除密钥吗? del() 似乎只支持 Table 和 OrderedTable.

非常感谢,

安德烈亚斯

Update: this has been marked as a bug, and fixed in e895bf7.

If you're on a Nim 1.0.6 setting a key to 0 updates the lenof the table, thanks to 29b6dd6.

CountTable.del() is included since Nim 1.2.0

您可以将要删除的key设置为0:

import tables

var tbl = toCountTable("aaabbb")
## tbl is {'a': 3, 'b': 3}

tbl['a'] = 0
## tbl now is {'b': 3}

echo tbl['a'] == 0
## true
echo tbl['c'] == 0
## true