Class: Yargi::Digraph::Vertex
- Inherits:
-
Object
- Object
- Yargi::Digraph::Vertex
- Includes:
- Markable
- Defined in:
- lib/yargi/digraph_vertex.rb
Overview
Vertex inside a digraph.
Methods add_in_edge, remove_in_edge, add_out_edge, remove_out_edge and index= are provided for Digraph itself and are not intended to be used directly.
Instance Attribute Summary collapse
-
#graph ⇒ Object
(also: #digraph)
readonly
Owning graph.
-
#index ⇒ Object
Index in the vertices list of the owner.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares indexes.
-
#add_in_edge(edge) ⇒ Object
Adds an incoming edge.
-
#add_out_edge(edge) ⇒ Object
Adds an outgoing edge.
-
#adjacent(filter = nil, &block) ⇒ Object
Returns all adjacent vertices.
-
#in_adjacent(filter = nil, &block) ⇒ Object
Returns back-adjacent vertices.
-
#in_edges(filter = nil, &block) ⇒ Object
Returns a copy of the incoming edges list.
-
#initialize(graph, index) ⇒ Vertex
constructor
Creates a vertex instance.
-
#inspect ⇒ Object
Inspects the vertex.
-
#out_adjacent(filter = nil, &block) ⇒ Object
Returns forward-adjacent vertices.
-
#out_edges(filter = nil, &block) ⇒ Object
Returns a copy of the outgoing edges list.
-
#remove_in_edge(edge) ⇒ Object
Removes an incoming edge.
-
#remove_out_edge(edge) ⇒ Object
Removes an outgoing edge.
-
#to_s ⇒ Object
Returns a string representation.
Methods included from Markable
#add_marks, #get_mark, #has_mark?, #set_mark, #tag, #to_h
Constructor Details
Instance Attribute Details
#graph ⇒ Object (readonly) Also known as: digraph
Owning graph
14 15 16 |
# File 'lib/yargi/digraph_vertex.rb', line 14 def graph @graph end |
#index ⇒ Object
Index in the vertices list of the owner
18 19 20 |
# File 'lib/yargi/digraph_vertex.rb', line 18 def index @index end |
Instance Method Details
#<=>(other) ⇒ Object
Compares indexes
81 82 83 84 |
# File 'lib/yargi/digraph_vertex.rb', line 81 def <=>(other) return nil unless Vertex===other and self.graph==other.graph self.index <=> other.index end |
#add_in_edge(edge) ⇒ Object
Adds an incoming edge
58 59 60 |
# File 'lib/yargi/digraph_vertex.rb', line 58 def add_in_edge(edge) @in_edges << edge end |
#add_out_edge(edge) ⇒ Object
Adds an outgoing edge
68 69 70 |
# File 'lib/yargi/digraph_vertex.rb', line 68 def add_out_edge(edge) @out_edges << edge end |
#adjacent(filter = nil, &block) ⇒ Object
Returns all adjacent vertices
40 41 42 |
# File 'lib/yargi/digraph_vertex.rb', line 40 def adjacent(filter=nil, &block) (in_adjacent(filter, &block) + out_adjacent(filter, &block)).uniq end |
#in_adjacent(filter = nil, &block) ⇒ Object
Returns back-adjacent vertices
45 46 47 |
# File 'lib/yargi/digraph_vertex.rb', line 45 def in_adjacent(filter=nil, &block) @in_edges.source.filter(filter, &block) end |
#in_edges(filter = nil, &block) ⇒ Object
Returns a copy of the incoming edges list.
30 31 32 |
# File 'lib/yargi/digraph_vertex.rb', line 30 def in_edges(filter=nil, &block) @in_edges.filter(filter, &block) end |
#inspect ⇒ Object
Inspects the vertex
93 |
# File 'lib/yargi/digraph_vertex.rb', line 93 def inspect; "V#{index}" end |
#out_adjacent(filter = nil, &block) ⇒ Object
Returns forward-adjacent vertices
50 51 52 |
# File 'lib/yargi/digraph_vertex.rb', line 50 def out_adjacent(filter=nil, &block) @out_edges.target.filter(filter, &block) end |
#out_edges(filter = nil, &block) ⇒ Object
Returns a copy of the outgoing edges list.
35 36 37 |
# File 'lib/yargi/digraph_vertex.rb', line 35 def out_edges(filter=nil, &block) @out_edges.filter(filter, &block) end |
#remove_in_edge(edge) ⇒ Object
Removes an incoming edge
63 64 65 |
# File 'lib/yargi/digraph_vertex.rb', line 63 def remove_in_edge(edge) @in_edges.delete(edge) end |
#remove_out_edge(edge) ⇒ Object
Removes an outgoing edge
73 74 75 |
# File 'lib/yargi/digraph_vertex.rb', line 73 def remove_out_edge(edge) @out_edges.delete(edge) end |
#to_s ⇒ Object
Returns a string representation
90 |
# File 'lib/yargi/digraph_vertex.rb', line 90 def to_s; "V#{index}" end |