A vertex in a {DependencyGraph} that encapsulates a {#name} and a {#payload}
@return [String] the name of the vertex
@return [Object] the payload the vertex holds
@return [Array<Object>] the explicit requirements that required
this vertex
@return [Boolean] whether the vertex is considered a root vertex
@return [Boolean] whether the vertex is considered a root vertex
@return [Array<Edge>] the edges of {#graph} that have ‘self` as their
{Edge#origin}
@return [Array<Edge>] the edges of {#graph} that have ‘self` as their
{Edge#destination}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 25
def initialize(name, payload)
@name = name.frozen? ? name : name.dup.freeze
@payload = payload
@explicit_requirements = []
@outgoing_edges = []
@incoming_edges = []
end
Initializes a vertex with the given name and payload. @param [String] name see {#name} @param [Object] payload see {#payload}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 106
def ==(other)
return true if equal?(other)
shallow_eql?(other) &&
successors.to_set == other.successors.to_set
end
@return [Boolean] whether the two vertices are equal, determined
by a recursive traversal of each {Vertex#successors}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 141
def _path_to?(other, visited = new_vertex_set)
return false unless visited.add?(self)
return true if equal?(other)
successors.any? { |v| v._path_to?(other, visited) }
end
@param [Vertex] other the vertex to check if there’s a path to @param [Set<Vertex>] visited the vertices of {#graph} that have been visited @return [Boolean] whether there is a path to ‘other` from `self`
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 62
def _recursive_predecessors(vertices = new_vertex_set)
incoming_edges.each do |edge|
vertex = edge.origin
next unless vertices.add?(vertex)
vertex._recursive_predecessors(vertices)
end
vertices
end
@param [Set<Vertex>] vertices the set to add the predecessors to @return [Set<Vertex>] the vertices of {#graph} where ‘self` is a
{#descendent?}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 88
def _recursive_successors(vertices = new_vertex_set)
outgoing_edges.each do |edge|
vertex = edge.destination
next unless vertices.add?(vertex)
vertex._recursive_successors(vertices)
end
vertices
end
@param [Set<Vertex>] vertices the set to add the successors to @return [Set<Vertex>] the vertices of {#graph} where ‘self` is an
{#ancestor?}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 151
def ancestor?(other)
other.path_to?(self)
end
Is there a path from ‘other` to `self` following edges in the dependency graph? @return whether there is a path following edges within this {#graph}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 125
def hash
name.hash
end
@return [Fixnum] a hash for the vertex based upon its {#name}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 100
def inspect
"#{self.class}:#{name}(#{payload.inspect})"
end
@return [String] a string suitable for debugging
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 157
def new_vertex_set
require 'set'
Set.new
end
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 132
def path_to?(other)
_path_to?(other)
end
Is there a path from ‘self` to `other` following edges in the dependency graph? @return whether there is a path following edges within this {#graph}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 49
def predecessors
incoming_edges.map(&:origin)
end
@return [Array<Vertex>] the vertices of {#graph} that have an edge with
`self` as their {Edge#destination}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 55
def recursive_predecessors
_recursive_predecessors
end
@return [Set<Vertex>] the vertices of {#graph} where ‘self` is a
{#descendent?}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 81
def recursive_successors
_recursive_successors
end
@return [Set<Vertex>] the vertices of {#graph} where ‘self` is an
{#ancestor?}
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 35
def requirements
(incoming_edges.map(&:requirement) + explicit_requirements).uniq
end
@return [Array<Object>] all of the requirements that required
this vertex
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 115
def shallow_eql?(other)
return true if equal?(other)
other &&
name == other.name &&
payload == other.payload
end
@param [Vertex] other the other vertex to compare to @return [Boolean] whether the two vertices are equal, determined
solely by {#name} and {#payload} equality
# File tmp/rubies/ruby-3.2.0/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 75
def successors
outgoing_edges.map(&:destination)
end
@return [Array<Vertex>] the vertices of {#graph} that have an edge with
`self` as their {Edge#origin}