Giraffe.Graph (giraffe v0.1.2)

Public interface for working with graphs. Delegates to specific implementations based on whether the graph is directed or undirected.

Summary

Types

edge()

@type edge() :: {vertex(), vertex(), weight()}

t()

@type t() :: %Giraffe.Graph{
  impl: Giraffe.Graph.Directed.t() | Giraffe.Graph.Undirected.t(),
  type: :directed | :undirected
}

vertex()

@type vertex() :: any()

weight()

@type weight() :: number()

Functions

add_edge(graph, from, to, weight \\ 1)

add_vertex(graph, vertex)

edges(graph)

get_paths(graph, start, finish)

get_shortest_path(graph, start, finish)

new(list)

@spec new(map()) :: t()

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}

vertices(graph)