class Gem::Molinillo::DependencyGraph::Vertex
{DependencyGraph} 中的一个顶点,封装了 {#name} 和 {#payload}
属性
@return [Array<Object>] 需要的显式需求
this vertex
@return [Array<Edge>] {#graph} 中以 “self” 作为起点的边
{Edge#destination}
@return [String] 顶点的名称
@return [Array<Edge>] {#graph} 中以 “self” 作为起点的边
{Edge#origin}
@return [Object] 顶点保存的负载
@return [Boolean] 顶点是否被视为根顶点
@return [Boolean] 顶点是否被视为根顶点
公共类方法
使用给定的名称和负载初始化顶点。@param [String] name 请参阅 {#name} @param [Object] payload 请参阅 {#payload}
# File rubygems/vendor/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
公共实例方法
@return [Boolean] 两个顶点是否相等,通过以下方式确定
by a recursive traversal of each {Vertex#successors}
# File rubygems/vendor/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
是否存在从 ‘other` 到 `self` 的路径,该路径遵循依赖关系图中的边? @return 是否存在遵循此 {#graph} 中的边的路径
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 151 def ancestor?(other) other.path_to?(self) end
@return [Fixnum] 基于其 {#name} 的顶点的哈希值
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 125 def hash name.hash end
@return [String] 适用于调试的字符串
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 100 def inspect "#{self.class}:#{name}(#{payload.inspect})" end
是否存在从 ‘self` 到 `other` 的路径,该路径遵循依赖关系图中的边? @return 是否存在遵循此 {#graph} 中的边的路径
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 132 def path_to?(other) _path_to?(other) end
@return [Array<Vertex>] {#graph} 中有边指向 `self` 的顶点
`self` as their {Edge#destination}
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 49 def predecessors incoming_edges.map(&:origin) end
@return [Set<Vertex>] {#graph} 中 ‘self` 是其后代的顶点集合
{#descendent?}
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 55 def recursive_predecessors _recursive_predecessors end
@return [Set<Vertex>] {#graph} 中 ‘self` 是其祖先的顶点集合
{#ancestor?}
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 81 def recursive_successors _recursive_successors end
@return [Array<Object>] 所有需要的需求
this vertex
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 35 def requirements (incoming_edges.map(&:requirement) + explicit_requirements).uniq end
@param [Vertex] other 要比较的另一个顶点 @return [Boolean] 两个顶点是否相等,通过以下方式确定
solely by {#name} and {#payload} equality
# File rubygems/vendor/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
@return [Array<Vertex>] {#graph} 中有边指向 `self` 的顶点
`self` as their {Edge#origin}
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 75 def successors outgoing_edges.map(&:destination) end
受保护的实例方法
@param [Vertex] other 要检查是否存在路径的顶点 @param [Set<Vertex>] visited 已访问的 {#graph} 顶点 @return [Boolean] 是否存在从 `self` 到 ‘other` 的路径
# File rubygems/vendor/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 [Set<Vertex>] vertices 要添加前置顶点的集合 @return [Set<Vertex>] {#graph} 中 ‘self` 是其后代的顶点
{#descendent?}
# File rubygems/vendor/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 要添加后继顶点的集合 @return [Set<Vertex>] {#graph} 中 ‘self` 是其祖先的顶点
{#ancestor?}
# File rubygems/vendor/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
私有实例方法
# File rubygems/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 157 def new_vertex_set require 'set' Set.new end