class RGL::BidirectionalAdjacencyGraph

This implementation of {BidirectionalGraph} creates an internal {DirectedAdjacencyGraph} to store the in-edges and overrides methods to ensure that the out and in graphs remain synchronized.

Public Class Methods

new(edgelist_class = Set, *other_graphs) click to toggle source

@see DirectedAdjacencyGraph#initialize

In super method the in edges are also added since {add_edge} of this class also inserts edges in ‘@reverse`.

Calls superclass method RGL::DirectedAdjacencyGraph::new
   # File lib/rgl/bidirectional_adjacency.rb
20 def initialize(edgelist_class = Set, *other_graphs)
21   @reverse = DirectedAdjacencyGraph.new(edgelist_class)
22   super(edgelist_class, *other_graphs)
23 end

Public Instance Methods

add_edge(u, v) click to toggle source

@see MutableGraph#add_edge.

Calls superclass method RGL::DirectedAdjacencyGraph#add_edge
   # File lib/rgl/bidirectional_adjacency.rb
32 def add_edge(u, v)
33   super(u, v)
34   @reverse.add_edge(v, u)
35 end
add_vertex(v) click to toggle source

@see MutableGraph#add_vertex.

Calls superclass method RGL::DirectedAdjacencyGraph#add_vertex
   # File lib/rgl/bidirectional_adjacency.rb
26 def add_vertex(v)
27   super(v)
28   @reverse.add_vertex(v)
29 end
each_in_neighbor(v, &b) click to toggle source

@see BidirectionalGraph#each_in_neighbor

   # File lib/rgl/bidirectional_adjacency.rb
57 def each_in_neighbor(v, &b)
58   @reverse.each_adjacent(v, &b)
59 end
has_in_edge?(u, v) click to toggle source

@see Graph#has_edge?

   # File lib/rgl/bidirectional_adjacency.rb
50 def has_in_edge?(u, v)
51   @reverse.has_edge?(u, v)
52 end
in_degree(v) click to toggle source

Returns the number of in-edges (for directed graphs) or the number of incident edges (for undirected graphs) of vertex v. @return [int]

   # File lib/rgl/bidirectional_adjacency.rb
70 def in_degree(v)
71   @reverse.out_degree(v)
72 end
in_neighbors(v) click to toggle source
   # File lib/rgl/bidirectional_adjacency.rb
63 def in_neighbors(v)
64   @reverse.adjacent_vertices(v)
65 end
remove_edge(u, v) click to toggle source

@see MutableGraph::remove_edge.

Calls superclass method RGL::DirectedAdjacencyGraph#remove_edge
   # File lib/rgl/bidirectional_adjacency.rb
44 def remove_edge(u, v)
45   super(u, v)
46   @reverse.remove_edge(v, u)
47 end
remove_vertex(v) click to toggle source

@see MutableGraph#remove_vertex.

   # File lib/rgl/bidirectional_adjacency.rb
38 def remove_vertex(v)
39   super(v)
40   @reverse.remove_vertex(v)
41 end