class DAG::Vertex

Attributes

dag[R]
payload[R]

Public Class Methods

new(dag, payload) click to toggle source
# File lib/dag/vertex.rb, line 8
def initialize(dag, payload)
  @dag = dag
  @payload = payload
end

Public Instance Methods

[](key) click to toggle source

Retrieve a value from the vertex's payload. This is a shortcut for vertex.payload.

@param key [Object] the payload key @return the corresponding value from the payload Hash, or nil if not found

# File lib/dag/vertex.rb, line 73
def [](key)
  @payload[key]
end
ancestors(result_set = Set.new) click to toggle source
# File lib/dag/vertex.rb, line 77
def ancestors(result_set = Set.new)
  predecessors.each do |v|
    unless result_set.include? v
      result_set.add(v)
      v.ancestors(result_set)
    end
  end
  return result_set
end
descendants(result_set = Set.new) click to toggle source
# File lib/dag/vertex.rb, line 87
def descendants(result_set = Set.new)
  successors.each do |v|
    unless result_set.include? v
      result_set.add(v)
      v.descendants(result_set)
    end
  end
  return result_set
end
has_ancestor?(other) click to toggle source

Is there a path from other to here following edges in the DAG?

@param [DAG::Vertex] another Vertex is the same DAG @raise [ArgumentError] if other is not a Vertex in the same DAG @return true iff there is a path following edges within this DAG

# File lib/dag/vertex.rb, line 58
def has_ancestor?(other)
  raise ArgumentError.new('You must supply a vertex in this DAG') unless
    is_vertex_in_my_dag?(other)
  predecessors.include?(other) || predecessors.any? {|v| v.has_ancestor?(other) }
end
Also aliased as: is_reachable_from?
has_descendant?(other)
Alias for: has_path_to?
has_descendent?(other)
Alias for: has_path_to?
has_path_to?(other) click to toggle source

Is there a path from here to other following edges in the DAG?

@param [DAG::Vertex] another Vertex is the same DAG @raise [ArgumentError] if other is not a Vertex in the same DAG @return true iff there is a path following edges within this DAG

# File lib/dag/vertex.rb, line 42
def has_path_to?(other)
  raise ArgumentError.new('You must supply a vertex in this DAG') unless
    is_vertex_in_my_dag?(other)
  successors.include?(other) || successors.any? {|v| v.has_path_to?(other) }
end
Also aliased as: has_descendant?, has_descendent?
incoming_edges() click to toggle source
# File lib/dag/vertex.rb, line 19
def incoming_edges
  @dag.edges.select {|e| e.destination == self}
end
inspect() click to toggle source
# File lib/dag/vertex.rb, line 31
def inspect
  "DAG::Vertex:#{@payload.inspect}"
end
is_reachable_from?(other)
Alias for: has_ancestor?
outgoing_edges() click to toggle source
# File lib/dag/vertex.rb, line 15
def outgoing_edges
  @dag.edges.select {|e| e.origin == self}
end
predecessors() click to toggle source
# File lib/dag/vertex.rb, line 23
def predecessors
  incoming_edges.map(&:origin).uniq
end
successors() click to toggle source
# File lib/dag/vertex.rb, line 27
def successors
  outgoing_edges.map(&:destination).uniq
end

Private Instance Methods

is_vertex_in_my_dag?(v) click to toggle source
# File lib/dag/vertex.rb, line 99
def is_vertex_in_my_dag?(v)
  v.kind_of?(Vertex) and v.dag == self.dag
end