Created
April 18, 2013 08:07
-
-
Save mvidner/5411039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
$deps = { | |
:network => [ :foo, :bar, :baz], | |
:foo => [:testsuite, :yast2], | |
:bar => [:yast2, :testsuite], | |
:baz => [:yast2, :testsuite], | |
:yast2 => [:testsuite], | |
:testsuite => [] | |
} | |
class Array | |
# For debugging, let's "mute" uniq. | |
# I cannot think of a reasonable implementation that would keep | |
# other element than the first occurring. | |
def evil_uniq | |
# uniq | |
dup | |
end | |
end | |
def transitive_deps0(target) | |
deps_of_deps = $deps[target].map { |d| transitive_deps0(d) } | |
(deps_of_deps.reduce([], :+) + $deps[target]).evil_uniq | |
end | |
def transitive_deps1(target) | |
deps_of_deps = $deps[target].map { |d| transitive_deps1(d) } | |
deps_of_deps.reduce($deps[target], :+).evil_uniq | |
end | |
puts "original" | |
p transitive_deps0(:network) | |
puts "reduced" | |
p transitive_deps1(:network) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment