When use hash function with ref object hashset not working correctly(if i 
remove ref (like pointer) its ok) , but when i've add == (equal) overload 
function its working perfect. How is nim language compare to pointer object? 
does it use adress of memory or something like that?

Example code like this: 
    
    
    type NM =  ref object of RootObj
        name*:string
    
    # i added this for working correctly
    proc `==` (a,b: NM):bool =
        a.name == b.name
    
    proc hash(nm:NM):Hash =
        return !$nm.name.hash
    
    
    proc `$`(nm:NM):string =
        return nm.name & " hash: " & $nm.hash
    
    
    var b = initHashSet[NM]()
    
    var
        f = NM(name: "XX")
        g = NM(name: "YY")
        h = NM(name: "XX")
    
    b.incl(f)
    b.incl(g)
    b.incl(f)
    b.incl(g)
    # b.incl(h)
    
    echo b.contains(h)
    
    
    echo $b
    
    
    Run

Reply via email to