Giraffe.Graph (giraffe v0.1.3)
Public interface for working with graphs. Delegates to specific implementations based on whether the graph is directed or undirected.
Summary
Functions
Creates a new graph.
Returns a list of vertices that are reachable from any of the given vertices.
Types
@type t() :: %Giraffe.Graph{ impl: Giraffe.Graph.Directed.t() | Giraffe.Graph.Undirected.t(), type: :directed | :undirected }
@type vertex() :: any()
@type weight() :: number()
Functions
Creates a new graph.
Options
:type
- The type of graph. Can be:directed
or:undirected
. Defaults to:directed
.
Examples
iex> Giraffe.Graph.new(type: :directed)
%Giraffe.Graph{impl: %Giraffe.Graph.Directed{vertices: MapSet.new([]), edges: %{}}, type: :directed}
iex> Giraffe.Graph.new(type: :undirected)
%Giraffe.Graph{impl: %Giraffe.Graph.Undirected{vertices: MapSet.new([]), edges: %{}}, type: :undirected}
Returns a list of vertices that are reachable from any of the given vertices.
Includes the starting vertices themselves as paths of length zero are allowed.
Examples
iex> g = Giraffe.Graph.new(type: :directed)
...> g = g |> Giraffe.Graph.add_edge(1, 2) |> Giraffe.Graph.add_edge(2, 3)
...> Giraffe.Graph.reachable(g, [1])
[1, 2, 3]
iex> g = Giraffe.Graph.new(type: :undirected)
...> g = g |> Giraffe.Graph.add_edge(1, 2) |> Giraffe.Graph.add_edge(2, 3)
...> Giraffe.Graph.reachable(g, [3])
[1, 2, 3]