class

CGL::AdjacencyGraph(V, W, L)

Inherits CGL::AdjacencyHash / CGL::AbstractGraph / CGL::AnyGraph / Reference / Object

A base class for adjacency list-based undirected 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)
Source
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, default_label : L | Nil = nil)
Source
new(edges : Enumerable(AnyEdge(V)), *, default_weight : W | Nil = nil, &block : -> L | Nil)
Source
new(edges : Enumerable(AnyEdge(V)), *, default_weight : W | Nil = nil, default_label : L | Nil = nil)
Source

Instance 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.

Source
degree_of(v : V) : Int32

Returns the degree of the given vertex v.

For directed graphs, the value equals #out_degree_of.

For undirected graphs, the value is the sum of #in_degree_of and #in_degree_of.

Source
remove_edge(u : V, v : V, &)
Source
remove_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
Source