# `Yog.Community.Result`
[🔗](https://github.com/code-shoily/yog_ex/blob/v0.97.0/lib/yog/community/result.ex#L1)

Result of community detection algorithms.

Represents a partition of nodes into non-overlapping communities, where
each node belongs to exactly one community.

## Fields

- `assignments` - Map from node ID to community ID
- `num_communities` - Total number of distinct communities
- `metadata` - Optional metadata (algorithm name, quality metrics, etc.)

## Examples

    iex> result = Yog.Community.Result.new(%{1 => 0, 2 => 0, 3 => 1})
    iex> result.num_communities
    2
    iex> result.assignments[1]
    0

# `community_id`

```elixir
@type community_id() :: any()
```

# `node_id`

```elixir
@type node_id() :: Yog.Model.node_id()
```

# `t`

```elixir
@type t() :: %Yog.Community.Result{
  assignments: %{required(node_id()) =&gt; community_id()},
  metadata: map(),
  num_communities: non_neg_integer()
}
```

# `from_map`

```elixir
@spec from_map(map()) :: t()
```

Backward compatibility: convert from legacy map format.

# `new`

```elixir
@spec new(%{required(node_id()) =&gt; community_id()}) :: t()
```

Creates a community result from an assignments map.

Automatically calculates the number of communities.

# `new`

```elixir
@spec new(%{required(node_id()) =&gt; community_id()}, map(), keyword()) :: t()
```

Creates a community result with explicit metadata and optional pre-computed values.

## Options

- `:num_communities` - Pre-computed community count to avoid re-scanning

## Examples

    iex> result = Yog.Community.Result.new(%{1 => 0, 2 => 0, 3 => 1}, %{}, num_communities: 2)
    iex> result.num_communities
    2

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

Convert to legacy map format (for gradual migration).

---

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