Class: Ryac::Pipeline::DependencyGraph

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Returns:

  • (Hash[String, Array[String]])


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.

Returns:



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.

Returns:

  • (Hash[String, Integer])


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.

Returns:

  • (Hash[String, String])


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

Parameters:

  • path (String)

Returns:



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

Parameters:

  • entry (FileEntry) —

    The file entry to add



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

Returns:

  • (Boolean)


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.

Returns:

  • (Array[String])


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

Returns:

  • (Array<String>)


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

Returns:

  • (Integer)


68
69
70
# File 'lib/ryac/pipeline/data_types.rb', line 68

def size
  @files.size
end