I have a cyclic graphical structure that is represented by Node objects. A Node is either a scalar value (leaf) or a list of n> = 1 nodes (inner node).
Due to possible circular references, I cannot just use the recursive function HashCode (), which combines the HashCode () of all the child nodes: it will end in infinite recursion.
Although the HashCode () part seems at least feasible by placing and ignoring already visited nodes, I am having some problems to think of a working and efficient algorithm for Equals ().
To my surprise, I did not find any useful information about this, but I am sure that many smart people thought of good ways to solve these problems ... right?
Example (python):
A = [ 1, 2, None ]; A[2] = AB = [ 1, 2, None ]; B[2] = B
A is equal to B because it represents exactly the same graph.
BTW. This question is not aimed at any particular language, but the implementation of hashCode () and equals () for the described Node object in Java will be a good practical example.
equals graph circular-reference hash
mfya
source share