Class: Hash

Inherits:
Object show all
Includes:
TSort
Defined in:
lib/dep_analyzer.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#minvertObject

Return the #inverse of a hash, allowing for multiple keys having the same values.



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dep_analyzer.rb', line 67

def minvert
  r = Hash.new { |h,k| h[k] = [] }
  invert.each do |keys, val|
    keys.each do |key|
      r[key] << val
    end
  end
  r.each do |k,v|
    r[k] = v.sort
  end
  r
end

#t(k) ⇒ Object

Calculates the (transitive) set of dependencies for a given key.



94
95
96
97
98
99
100
# File 'lib/dep_analyzer.rb', line 94

def t(k)
  r = Set.new
  self[k].each do |v|
    r.push(v, *t(v))
  end
  r.to_a.sort
end

#transitiveObject

Calculate the transitive closure of the hash.



83
84
85
86
87
88
89
# File 'lib/dep_analyzer.rb', line 83

def transitive
  r = Hash.new { |h,k| h[k] = [] }
  each do |k,v|
    r[k].push(*t(k))
  end
  r
end

#tsort_each_child(node, &block) ⇒ Object



59
60
61
# File 'lib/dep_analyzer.rb', line 59

def tsort_each_child(node, &block)
  fetch(node).each(&block)
end