Skip to Main Content
Exploring Graphs with Elixir
book

Exploring Graphs with Elixir

by Tony Hammond
November 2022
Intermediate to advanced content levelIntermediate to advanced
294 pages
5h 58m
English
Pragmatic Bookshelf
Content preview from Exploring Graphs with Elixir

Basic Workout

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.

Directed Graph

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: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Concurrent Data Processing in Elixir

Concurrent Data Processing in Elixir

Svilen Gospodinov

Publisher Resources

ISBN: 9798888650059Errata Page