Search code examples
hashsetnim-lang

Hashset in Nim-lang


I am trying to use HashSet type of nim-lang but receiving error

var list = initSet\[int]()

and error is

Error: undeclared identifier: 'initSet'

I have already imported hashes library


Solution

  • It's in the sets module, not hashes.

    import sets
    
    proc sum(xs: HashSet[int]): int =
      for x in xs:
        result += x
    
    var list = initHashSet[int]()
    list.incl(10)
    list.incl(20)
    list.incl(30)
    
    echo list.sum