CountTable doesn't support the '==' operator #4901

konqoro opened this Issue Oct 16, 2016 · 1 comment


None yet

1 participant

konqoro commented Oct 16, 2016 edited
import tables

var t = ['r', 'a', 'p', 't', 'u'].toCountTable
var s = ['r', 'a', 'p', 't', 'u'].toCountTable
echo t == s

Compilers complains:

bug.nim(6, 8) template/generic instantiation from here
lib/nim/system.nim(2276, 8) Error: undeclared field: 'data'

konqoro commented Oct 20, 2016 edited

A workaround using sequtils

proc `==`*[A](s, t: CountTable[A]): bool =
    let seq1 = toSeq(s.pairs)
    let seq2 = toSeq(t.pairs)
    if len(seq1) == len(seq2):
        for i in seq1:
            if i notin seq2: return false
        return true
@Araq Araq pushed a commit that closed this issue Oct 24, 2016
@flyx flyx Table fixes. fixes #4901
 * added `==` for OrderedTable, CountTable and the *Ref types
 * added missing documentation to all `==` procs
 * fixed clear() for OrderedTables, which did not work because `var`
   does not work well with `|`
 * added tests
@Araq Araq closed this in 73b0bb5 Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment