From: Massimiliano Mirra Date: 2002-09-17T10:30:30+09:00 Subject: Re: Dependency "trees" - suggestions? On Tue, Sep 17, 2002 at 03:33:24AM +0900, GOTO Kentaro wrote: > > So this is a DAG "Directed Acyclic Graph" for which there many algorithms > > available. > FYI: Ruby 1.7.x has tsort.rb as a standard library. *Sound of head banging against the wall* Why do I always wait so long before asking the List? tsort.rb looks just like the perfect solution for the lazy me. I particularly like this: "If there is a cycle, (({TSort::Cyclic})) is raised." :-) I'm trying it in 1.6 and I get two test failures. This is the first: Failure occurred in test_cycle(TSortTest) [/home/bard/lib/ruby/runit/assert.rb:56]: Expected exception to be of type but was [2], 2=>[3, 4], 3=>[2], 4=>[]} assert_equal([[4], [2, 3], [1]], h.strongly_connected_components.map {|nodes| nodes.sort}) assert_exception(TSort::Cyclic) { h.tsort } # <----- end I looked at TSort::tsort but couldn't see where a block was required. Massimiliano