go ahead... be a heretic | |
PerlMonks |
Re: Sort mechanics problems with objects and potentially contradicting comparisons (would cause infinite loop)by FloydATC (Deacon) |
on Jun 02, 2016 at 10:56 UTC ( [id://1164748]=note: print w/replies, xml ) | Need Help?? |
I would say that the task of detecting circular references in a data structure does not involve sorting at all. Simply walk the data structure/hierarchy/whatever while keeping track of the path you followed to get there. Here's some untested code to show what I mean:
This can be done recursively or in a linear fashion if this suits you better. Modules already exist but writing your own code would probably be faster than trying to fit an existing module with your particular data.
-- FloydATC
Time flies when you don't know what you're doing
In Section
Seekers of Perl Wisdom
|
|