Skip to content

Bug with CountTable []= 0 #13079

Closed
Closed
@Titousensei

Description

@Titousensei

I think I found a bug with CountTable. In some conditions, when changing the count of one item to zero, the table gets corrupted and another item is set to zero when doing a table lookup (but not from iterator).

Here's a small repro:

import tables

var t = initCountTable[string]()
t[" a s </w> "] = 40335062
t[" t h e r e </w> "] = 23199253
t[" p l a y </w> "] = 7258802
echo t.len

t[" t h e r e </w> "] = 0
echo t.len
echo t

for word, freq in t:
    echo word, "|", freq, " ", t[word]

prints the following:

3
3
{" a s </w> ": 40335062, " p l a y </w> ": 7258802}
 a s </w> |40335062 40335062
 p l a y </w> |7258802 0

As you can see, freq from the iterator is correct, but t[word] is zero.

Also, the len did not change and is inconsistent with the printed table. ( existing issue #12813 )

This is with nim 1.0.4. I can see that upcoming 1.0.6 will have del implemented to replace []= 0, and that might fix this bug. (Or maybe not.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions