Today I got a very strange output from my app. After digging, I found the bug is in the CountTable.
import tables
var ct = initCountTable[int]()
ct.inc(130, 1)
ct.inc(132, 1)
ct.inc(258, 1)
ct.inc(131, 100)
echo ct[131] # should output 100
ct.inc(132, -1)
echo ct[131] # should output 100, too
0
100
Nim Compiler Version 0.20.99 [Windows: amd64]
Thanks for using the issue template and coming up with the precise* small example of the problem. It really makes debugging much easier.
* because even small changes don't exhibit this behaviour — this bug has been with us for a very long time, and only now somebody has spotted it.
You really can't count negative values like that... The CountTable is designed that 0 occurrences are not stored.
You really can't count negative values like that... The CountTable is designed that 0 occurrences are not stored.
You mean CountTable cannot inc() negative value or cannot store negative value?
However, I still cannot understand why access [132] will influence the value in [131].
inc should take a Positive number, yes.
That should be documented, and the argument of inc should be a Natural then
That should be documented, and the argument of
incshould be aNaturalthen
Most helpful comment
That should be documented, and the argument of
incshould be a Natural then