Anonymous user
Topological sort/Extracted top item: Difference between revisions
Topological sort/Extracted top item (view source)
Revision as of 20:22, 27 August 2020
, 3 years ago→{{header|REXX}}: added/changed comments and whitespace, split a DO group statement.
m (added Category:Sorting) |
m (→{{header|REXX}}: added/changed comments and whitespace, split a DO group statement.) |
||
Line 1,020:
<lang REXX>/*REXX program displays the compile order of jobs (indicating the dependencies). */
parse arg job /*obtain optional argument from the CL.*/
jobL.
tree.
tree.2= ' top2 des1 ip2 ip3 '
tree.3= ' ip1 extra1 ip1a ipcommon '
Line 1,030:
$=
do j=1 while tree.j\=='' /*build job tree.*/
parse var tree.j x deps; @.x= space(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*/
!.=; !!.= !. /*init. 2 arrays.*/
do j=1 for words($); x= word($, j);
do k=1 for !.x.0; !.x.k= word(@.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);
if z==0 then do; #.x=1; iterate; end /*if no dependents, then skip this one.*/
do k=1 for z;
if datatype(y, 'W') then m= max(m, y)
else do; allN=
if #.y\==0 then !.x.k= #.y
end /* [↑] replace with a number. */
end /*k*/
if allN & m\==0 then #.x= max(#.x, m + 1)
end /*j*/
end /*words($)*/
if job='' then job= word(tree.1, 1)
jobL.1=
s=
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*/ /* [↑] Duplicate? Then delete it. */
end /*r*/
jobL.j= yyy
if yyy='' then leave /*if null, then we're done with jobList*/
z= words(yyy)
s= s+1
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
end /*k*/
do s=1 for words(JL); _= word(JL,
stage.level= stage.level _ /*assign a level to job stage number. */
end /*s*/ /* [↑] construct various job stages. */
|