Wed 29 Jun 2016 02:52:21 AM UTC, comment #3:
I don't think this is trivial.
The issue is that
is assigning handles to the objects, rather than assigning values. That gives rise to a closed loop: a.parent.child = a. Naively walking that structure as a tree gives the loop.
If we repeat that with
then to compare isequal(a, c), we need _isequal_ to learn the actual structure (since we can't simply rely on checking that the "rep" is the same, which was my first thought).
It isn't even clear what _isequal_(a,c) should be. Either "true" or "false" is self-consistent.
Perhaps we can still walk the tree keeping track of the rep values we have seen. If one finds the n'th rep again and the other also finds the n'th rep at the same point, we report success without the recursive call. If one finds the n'th rep again and the other doesn't, we return false.
That will consume a huge amount of memory when comparing large trees. It would be helped slightly if a persistent variable is used, so we don't need the list of visited nodes in each stack frame.
I'm reassigning this from "crash" to "Matlab compatibility". (There is still no way to distinguish a very dangerous silent "incorrect result" from something that simply reports an error.)
|