Class: Ryac::Pipeline::DependencyGraph
- Inherits:
-
Object
- Object
- Ryac::Pipeline::DependencyGraph
- Defined in:
- lib/ryac/pipeline/data_types.rb,
sig/ryac/pipeline/data_types.rbs
Overview
Represents the dependency relationships between files Uses adjacency list for efficient topological sort
Instance Attribute Summary collapse
-
#adjacency ⇒ Hash[String, Array[String]]
readonly
Returns the value of attribute adjacency.
-
#files ⇒ Hash[String, FileEntry]
readonly
Returns the value of attribute files.
-
#in_degrees ⇒ Hash[String, Integer]
readonly
Returns the value of attribute in_degrees.
-
#rbs_files ⇒ Hash[String, String]
readonly
Returns the value of attribute rbs_files.
Instance Method Summary collapse
-
#[](path) ⇒ FileEntry?
Get file entry by path.
-
#add_file(entry) ⇒ void
Add a file entry to the graph.
-
#empty? ⇒ Boolean
Check if graph is empty.
-
#initialize ⇒ DependencyGraph
constructor
A new instance of DependencyGraph.
-
#lazy_paths ⇒ Array[String]
The files bundled as lazy regions, in path order.
-
#paths ⇒ Array<String>
Get all file paths in the graph.
-
#size ⇒ Integer
Number of files in the graph.
Constructor Details
#initialize ⇒ DependencyGraph
Returns a new instance of DependencyGraph.
26 27 28 29 30 31 |
# File 'lib/ryac/pipeline/data_types.rb', line 26 def initialize @files = {} # Hash<String, FileEntry>: path -> entry mapping @adjacency = {} # Hash<String, Array<String>>: path -> dependent paths (files that require this one) @in_degrees = {} # Hash<String, Integer>: path -> number of dependencies @rbs_files = {} # Hash<String, String>: path -> RBS content end |
Instance Attribute Details
#adjacency ⇒ Hash[String, Array[String]] (readonly)
Returns the value of attribute adjacency.
24 25 26 |
# File 'lib/ryac/pipeline/data_types.rb', line 24 def adjacency @adjacency end |
#files ⇒ Hash[String, FileEntry] (readonly)
Returns the value of attribute files.
24 25 26 |
# File 'lib/ryac/pipeline/data_types.rb', line 24 def files @files end |
#in_degrees ⇒ Hash[String, Integer] (readonly)
Returns the value of attribute in_degrees.
24 25 26 |
# File 'lib/ryac/pipeline/data_types.rb', line 24 def in_degrees @in_degrees end |
#rbs_files ⇒ Hash[String, String] (readonly)
Returns the value of attribute rbs_files.
24 25 26 |
# File 'lib/ryac/pipeline/data_types.rb', line 24 def rbs_files @rbs_files end |
Instance Method Details
#[](path) ⇒ FileEntry?
Get file entry by path
62 63 64 |
# File 'lib/ryac/pipeline/data_types.rb', line 62 def [](path) @files[path] end |
#add_file(entry) ⇒ void
This method returns an undefined value.
Add a file entry to the graph
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ryac/pipeline/data_types.rb', line 40 def add_file(entry) @files[entry.path] = entry @adjacency[entry.path] ||= [] @in_degrees[entry.path] ||= 0 # Update adjacency and in-degrees based on all dependencies (entry.dependencies + entry.in_class_dependencies).each do |dep_path| @adjacency[dep_path] ||= [] @adjacency[dep_path] << entry.path @in_degrees[entry.path] += 1 end end |
#empty? ⇒ Boolean
Check if graph is empty
74 75 76 |
# File 'lib/ryac/pipeline/data_types.rb', line 74 def empty? @files.empty? end |
#lazy_paths ⇒ Array[String]
The files bundled as lazy regions, in path order.
34 35 36 |
# File 'lib/ryac/pipeline/data_types.rb', line 34 def lazy_paths @files.each_value.select(&:lazy).map(&:path).sort end |
#paths ⇒ Array<String>
Get all file paths in the graph
55 56 57 |
# File 'lib/ryac/pipeline/data_types.rb', line 55 def paths @files.keys end |
#size ⇒ Integer
Number of files in the graph
68 69 70 |
# File 'lib/ryac/pipeline/data_types.rb', line 68 def size @files.size end |