Skip to content

Instantly share code, notes, and snippets.

@mvidner
Created April 18, 2013 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidner/5411039 to your computer and use it in GitHub Desktop.
Save mvidner/5411039 to your computer and use it in GitHub Desktop.
#! /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