On Thu, Jul 27, 2017 at 09:36:31AM -0700, howardcs...@gmail.com wrote:
> https://golang.org/pkg/reflect/#DeepEqual
> 
> "Pointer values are deeply equal if they are equal using Go's == operator 
> or if they point to deeply equal values."
> 
> By the rules described here, the fact that both pointers have the same 
> value means it does not even NEED to check what they point to, so I don't 
> think it ever even sees the cycle.

You are right about that, but that's a vastly simplified example
to show the basic idea of what I'm talking about. In reality, there
are no common components.

> 
> So yeah, you would have to write your own implementation, or find one.

It's actually easy to do: You simply number the nodes, or well, the
memory locations being pointed to:

type state struct {
        lhsm, rhsm map[interface{}] int
        lhsc, rhsc int
}

Algorithm for comparing two pointers.

if lhsm[left side pointer] == 0 {
        lhsc++  // First counter is 1.
        lhsm[left side pointer] = lhsc
}
... same for right ...
return lhsm[left side ptr] == rhsm[right side ptr]

Obviously you still have to do the recursion.

I guess I should try to write that.
-- 
Debian Developer - deb.li/jak | jak-linux.org - free software dev
                  |  Ubuntu Core Developer |
When replying, only quote what is necessary, and write each reply
directly below the part(s) it pertains to ('inline').  Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to