November 2022
Intermediate to advanced
294 pages
5h 58m
English
Let’s first give the libgraph package a simple workout just to kick the tires.
As previously noted, the libgraph package uses the Graph module as its base namespace. This module defines a graph data structure, which supports directed and undirected graphs, in both acyclic and cyclic forms. It also defines the API for creating, manipulating, and querying that structure.
Let’s cd back to our ExGraphsBook root and open up IEx:
| | $ iex -S mix |
Create a new directed graph:
| | iex> g = Graph.new |
| | #Graph<type: directed, vertices: [], edges: []> |
Note that this is of type directed by default.
We can inspect the graph with the info/1 function:
| | iex> Graph.info(g) |
| | %{num_edges: 0, num_vertices: ... |