An algorithm and an implementation that can quickly find (ideally O(n)) whether or not a match between two sets exists is the first step of this issue. The second part is finding a way to both find and represent the possible matches between two sets. There probably exists an O(n) time algorithm for this too with some cleverness. Perhaps a good starting point is looking at algorithms relating to permutation functions and cyclic representation? Fundamentally a set of matches could hypothetically be thought of as a permutation cycle. Another way to look at it is that each node contains a set of potential matches, which then go through a logical elimination process by using singleton sets to remove elements which are already known to match a single other node.
An algorithm and an implementation that can quickly find (ideally O(n)) whether or not a match between two sets exists is the first step of this issue. The second part is finding a way to both find and represent the possible matches between two sets. There probably exists an O(n) time algorithm for this too with some cleverness. Perhaps a good starting point is looking at algorithms relating to permutation functions and cyclic representation? Fundamentally a set of matches could hypothetically be thought of as a permutation cycle. Another way to look at it is that each node contains a set of potential matches, which then go through a logical elimination process by using singleton sets to remove elements which are already known to match a single other node.