# `Yog.Multi.Graph`
[🔗](https://github.com/code-shoily/yog_ex/blob/v0.97.1/lib/yog/multi/graph.ex#L1)

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 store
- `out_edge_ids`: NodeId → [EdgeId] — outgoing edges per node
- `in_edge_ids`: NodeId → [EdgeId] — incoming edges per node

## Fields

- `kind` - Either `:directed` or `:undirected`
- `nodes` - Map from node ID to node data
- `edges` - Map from edge ID to `{from, to, data}`
- `out_edge_ids` - Map from node ID to MapSet of edge IDs
- `in_edge_ids` - Map from node ID to MapSet of edge IDs
- `next_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

# `edge_id`

```elixir
@type edge_id() :: non_neg_integer()
```

# `t`

```elixir
@type t() :: %Yog.Multi.Graph{
  edges: %{
    required(edge_id()) =&gt; {Yog.Model.node_id(), Yog.Model.node_id(), term()}
  },
  in_edge_ids: %{required(Yog.Model.node_id()) =&gt; MapSet.t(edge_id())},
  kind: :directed | :undirected,
  next_edge_id: non_neg_integer(),
  nodes: %{required(Yog.Model.node_id()) =&gt; term()},
  out_edge_ids: %{required(Yog.Model.node_id()) =&gt; MapSet.t(edge_id())}
}
```

# `directed`

```elixir
@spec directed() :: t()
```

Creates a new empty directed multigraph.

# `edge_count`

```elixir
@spec edge_count(t()) :: non_neg_integer()
```

Returns the total number of edges (including parallel edges).

# `new`

```elixir
@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

# `undirected`

```elixir
@spec undirected() :: t()
```

Creates a new empty undirected multigraph.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
