The function will take a list of component "dependencies", such as those structures that occur within
make, or
rpm, or even
CPAN, and produce a sorted listing of components ordered by precedence. Those that are required first are listed first.
The input to the function is a hash-list structured as "component" => list-of-requirements. An example is:
my @list = f(
a => [ 'b', 'c' ],
b => [ 'c', 'd' ],
c => [ 'd' ],
e => [ 'b', 'a' ],
f => undef,
);
All components involved in the calculation will be specified either explicitly, such as 'f' which is listed as having no dependencies, or implicitly, such as 'd' which is listed as a dependency of 'c'. The input data is not restricted to simple letters, though, as 'a' could just as easily be 'main.c', 'XML::Parser' or something more exotic, though a scalar nonetheless.
A sample output list would be something like:
'd','c','b','a','e','f'
Though note that 'f' could come anywhere in the list, since it has no dependencies and nothing is dependent on it. However, for most others their order is more fixed because of their respective dependencies.
Circular references are not considered valid input data, so they don't have to be handled.
I have a solution I am "golfifying" presently.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.