Core multigraph data structure.
A multigraph allows multiple (parallel) edges between the same pair of nodes. Both directed and undirected variants are supported.
The internal representation keeps three indexes:
edges: EdgeId → {from, to, data} — canonical edge storeout_edge_ids: NodeId → [EdgeId] — outgoing edges per nodein_edge_ids: NodeId → [EdgeId] — incoming edges per node
Fields
kind- Either:directedor:undirectednodes- Map from node ID to node dataedges- Map from edge ID to{from, to, data}out_edge_ids- Map from node ID to MapSet of edge IDsin_edge_ids- Map from node ID to MapSet of edge IDsnext_edge_id- Counter for generating unique edge IDs
Examples
iex> multi = Yog.Multi.Graph.new(:directed)
iex> multi.kind
:directed
iex> multi.next_edge_id
0
Summary
Functions
Creates a new empty directed multigraph.
Returns the total number of edges (including parallel edges).
Creates a new empty multigraph of the given type.
Creates a new empty undirected multigraph.
Types
@type edge_id() :: non_neg_integer()
@type t() :: %Yog.Multi.Graph{ edges: %{ required(edge_id()) => {Yog.Model.node_id(), Yog.Model.node_id(), term()} }, in_edge_ids: %{required(Yog.Model.node_id()) => MapSet.t(edge_id())}, kind: :directed | :undirected, next_edge_id: non_neg_integer(), nodes: %{required(Yog.Model.node_id()) => term()}, out_edge_ids: %{required(Yog.Model.node_id()) => MapSet.t(edge_id())} }
Functions
@spec directed() :: t()
Creates a new empty directed multigraph.
@spec edge_count(t()) :: non_neg_integer()
Returns the total number of edges (including parallel edges).
@spec new(:directed | :undirected) :: t()
Creates a new empty multigraph of the given type.
Examples
iex> multi = Yog.Multi.Graph.new(:directed)
iex> multi.kind
:directed
iex> Enum.count(multi.nodes)
0
iex> multi = Yog.Multi.Graph.new(:undirected)
iex> multi.kind
:undirected
@spec undirected() :: t()
Creates a new empty undirected multigraph.