CGL::AdjacencyDiGraph(V, W, L)
Inherits CGL::AdjacencyHash / CGL::AbstractDiGraph / CGL::AnyGraph / Reference / Object
A base class for adjacency list-based directed graphs
Constructors
new(vertices : Enumerable(V) | Nil = nil, edges : Enumerable(Tuple(V, V)) | Nil = nil, weights : Enumerable(W) | Nil = nil, labels : Enumerable(L | Nil) | Nil = nil, *, default_weight : W | Nil = nil, &block : -> L | Nil)
Sourcenew(vertices : Enumerable(V) | Nil = nil, edges : Enumerable(Tuple(V, V)) | Nil = nil, weights : Enumerable(W) | Nil = nil, labels : Enumerable(L | Nil) | Nil = nil, *, default_weight : W | Nil = nil, default_label : L | Nil = nil)
Sourcenew(edges : Enumerable(AnyEdge(V)), *, default_weight : W | Nil = nil, default_label : L | Nil = nil)
SourceInstance methods
add_edge(u : V, v : V, weight : W = self.default_weight, label : L | Nil = self.default_label)
Add an edge between vertices u and v.
The given vertices are automatically added if they are not already part of the graph.
A weight and/or a label can be associated to the edge if the concrete class supports it.
Returns the incoming degree of the given vertex v.
For undirected graphs, the value equals #degree_of.
Returns the outgoing degree of the given vertex v.
For undirected graphs, the value equals #degree_of.
remove_edge(u : V, v : V, &)
Sourceremove_vertex(v : V)
Remove given vertex v from this graph. Edges incident to v are also removed.
Raises a GraphError if vertex is not part of the graph.
g = CGL::Graph(String).new(edges: [{"a", "b"}, {"b", "c"}])
g.size # => 2
g.remove_vertex("b")
g.size # => 0