Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -30,3 +30,12 @@ synopsys </pre>
|
|||
<small>Note: the above data would be un-orderable if, for example, <code>dw04</code> is added to the list of dependencies of <code>dw01</code>.</small>
|
||||
|
||||
C.f: [[Topological sort/Extracted top item]].
|
||||
|
||||
There are two popular algorithms for topological sorting:
|
||||
Kahn's 1962 topological sort, and depth-first search.
|
||||
<ref>
|
||||
[[wp: topological sorting]]
|
||||
</ref><ref>
|
||||
Jason Sachs
|
||||
[http://www.embeddedrelated.com/showarticle/799.php "Ten little algorithms, part 4: topological sort"].
|
||||
</ref>
|
||||
|
|
|
|||
37
Task/Topological-sort/Fortran/topological-sort-3.f
Normal file
37
Task/Topological-sort/Fortran/topological-sort-3.f
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
subroutine tsort(nl,nd,idep,iord,no)
|
||||
|
||||
implicit none
|
||||
|
||||
integer,intent(in) :: nl
|
||||
integer,intent(in) :: nd
|
||||
integer,dimension(nd,2),intent(in) :: idep
|
||||
integer,dimension(nl),intent(out) :: iord
|
||||
integer,intent(out) :: no
|
||||
|
||||
integer :: i,j,k,il,ir,ipl,ipr,ipos(nl)
|
||||
|
||||
do i=1,nl
|
||||
iord(i)=i
|
||||
ipos(i)=i
|
||||
end do
|
||||
k=1
|
||||
do
|
||||
j=k
|
||||
k=nl+1
|
||||
do i=1,nd
|
||||
il=idep(i,1)
|
||||
ir=idep(i,2)
|
||||
ipl=ipos(il)
|
||||
ipr=ipos(ir)
|
||||
if (il==ir .or. ipl>=k .or. ipl<j .or. ipr<j) cycle
|
||||
k=k-1
|
||||
ipos(iord(k))=ipl
|
||||
ipos(il)=k
|
||||
iord(ipl)=iord(k)
|
||||
iord(k)=il
|
||||
end do
|
||||
if (k<=j) exit
|
||||
end do
|
||||
no=j-1
|
||||
|
||||
end subroutine tsort
|
||||
|
|
@ -1,8 +1,16 @@
|
|||
depSort=: monad define
|
||||
parsed=. <@;:;._2 y
|
||||
names=. {.&>parsed
|
||||
depends=. (-.L:0"_1 #,.i.@#) names i.L:1 parsed
|
||||
depends=. (~.@,&.> ;@:{L:0 1~)^:_ depends
|
||||
assert.-.1 e. (i.@# e.S:0"0 ])depends
|
||||
(-.&names ~.;parsed),names /: #@> depends
|
||||
)
|
||||
>dependencySort dependencies
|
||||
std
|
||||
ieee
|
||||
dware
|
||||
gtech
|
||||
ramlib
|
||||
std_cell_lib
|
||||
synopsys
|
||||
dw02
|
||||
dw05
|
||||
dw06
|
||||
dw07
|
||||
dw01
|
||||
dw04
|
||||
dw03
|
||||
des_system_lib
|
||||
|
|
|
|||
3
Task/Topological-sort/J/topological-sort-3.j
Normal file
3
Task/Topological-sort/J/topological-sort-3.j
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
dependencySort dependencies,'dw01 dw04',LF
|
||||
|assertion failure: dependencySort
|
||||
| -.1 e.(<0 1)|:depends
|
||||
8
Task/Topological-sort/J/topological-sort-4.j
Normal file
8
Task/Topological-sort/J/topological-sort-4.j
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
depSort=: monad define
|
||||
parsed=. <@;:;._2 y
|
||||
names=. {.&>parsed
|
||||
depends=. (-.L:0"_1 #,.i.@#) names i.L:1 parsed
|
||||
depends=. (~.@,&.> ;@:{L:0 1~)^:_ depends
|
||||
assert.-.1 e. (i.@# e.S:0"0 ])depends
|
||||
(-.&names ~.;parsed),names /: #@> depends
|
||||
)
|
||||
|
|
@ -9,8 +9,7 @@ end
|
|||
|
||||
depends = {}
|
||||
DATA.each do |line|
|
||||
libs = line.split(' ')
|
||||
key = libs.shift
|
||||
key, *libs = line.split
|
||||
depends[key] = libs
|
||||
libs.each {|lib| depends[lib] ||= []}
|
||||
end
|
||||
|
|
@ -20,7 +19,7 @@ begin
|
|||
depends["dw01"] << "dw04"
|
||||
p depends.tsort
|
||||
rescue TSort::Cyclic => e
|
||||
puts "cycle detected: #{e}"
|
||||
puts "\ncycle detected: #{e}"
|
||||
end
|
||||
|
||||
__END__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue