Anonymous user
Topological sort/Extracted top item: Difference between revisions
Topological sort/Extracted top item (view source)
Revision as of 21:11, 28 October 2017
, 6 years ago→{{header|REXX}}: added/changed comments and whitespace, allowed the use of a default job, used a template for the OUTPUTs..
m (changed ;C.f.: to ;Related task: (bold) header.) |
m (→{{header|REXX}}: added/changed comments and whitespace, allowed the use of a default job, used a template for the OUTPUTs..) |
||
Line 778:
Where the compile order between a subset of files is arbitrary, they are shown on the same line.
<br>This REXX version can handle multiple top levels.
<lang REXX>/*REXX program
parse arg job /*obtain optional argument from the CL.*/
jobL. =; stage.=; #.=0; @.=; JL=
tree.
tree.
tree.
tree.
tree.
▲tree.7= ' des1c des1c1 extra1 '
$=
do j=1 while tree.j\=='' /*build job tree.*/
parse var tree.j x deps;
if wordpos(x, $)==0 then $=$ x
do k=1 for words(@.x); _=word(@.x, k)
if wordpos(_, $)==0 then $=space($ _)
end /*k*/
end /*j*/
!.=; !!.=
do j=1 for words($); x=word($, j); !.x.0=words(@.x)
do k=1 for !.x.0; !.x.k=word(@.x, k); !!.x.k=!.x.k
end /*k*/ /* [↑] build arrays of job departments*/
end /*j*/
do words($) /*process all the jobs specified. */
do j=1 for words($); x=word($, j); z=words(@.x); allN=1; m=0
if z==0 then do; #.x=1; iterate; end /*if no dependents, then skip this one.*/
do k=1 for z; y=!.x.k
if datatype(y, 'W') then m=max(m, y)
else do; allN=0
if #.y\==0 then !.x.k=#.y
end /*k*/
if allN & m\==0 then #.x=max(#.x, m + 1)
end /*j*/ /* [↑] maybe set the stage number. */
end /*words($)*/
if job='' then job=word(tree.1, 1) /*Not specified? Use 1st job in tree.*/
jobL.1=job /*define the bottom level jobList. */
s=1 /*define the stage level for jobList. */
do j=1; yyy=jobL.j
do r=1 for words(yyy) /*verify that there are no duplicates. */
do c=1 while c<words(yyy); z=word(yyy,c)
p=wordpos(z, yyy, c + 1); if p\==0 then yyy=delword(yyy, p, 1)
end /*c*/ /* [↑]
end /*r*/
jobL.j=yyy
Line 828:
z=words(yyy) /*number of jobs in the jobList. */
s=s+1 /*bump the stage number. */
do k=1 for z; _=word(yyy, k)
jobL.s=jobL.s @._
end /*k*/
end /*j*/
do k=1 for s; JL=JL jobL.k;
do s=1 for words(JL) /*process each job in the jobList.
_=word(JL, s); level=#._
stage.level= stage.level _
end /*s*/ /* [↑] construct various job stages. */
say '─────── The compile order for job: ' job " ────────"; say
/* [↓] display the stages for the job.*/
do show=1 for s; if stage.show\=='' then say show stage.show
end
<pre>
─────── The compile order for job: top1 ───────
1 des1b extra1 ip1a ipcommon ip2a ip2b ip2c des1a1 des1a2 des1c1 extra1
Line 853:
4 top1
</pre>
<pre>
─────── The compile order for job: top2 ───────
1 ip3 des1b ip2a ip2b ip2c ipcommon des1a1 des1a2 des1c1 extra1
Line 862:
4 top2
</pre>
<pre>
─────── The compile order for job: top1 top2 ───────
1 ip3 des1b extra1 ip1a ipcommon ip2a ip2b ip2c des1a1 des1a2 des1c1 extra1
|