# `ExDatalog.Compiler.Stratifier`
[🔗](https://github.com/thanos/ex_datalog/blob/v0.5.0/lib/ex_datalog/compiler/stratifier.ex#L1)

Assigns strata to relations and rules in a validated Datalog program.

Uses `ExDatalog.Validator.Stratification` for SCC computation and
stratum assignment. This module bridges the validator and the IR compiler,
producing a deterministic stratum assignment that the engine uses to
evaluate strata in order.

# `assign`

```elixir
@spec assign(ExDatalog.Program.t()) :: %{
  required(non_neg_integer()) =&gt; non_neg_integer()
}
```

Assigns a stratum to each rule in the program.

Returns a map from rule index (0-based, in canonical order) to its
stratum number. Rules are ordered by their position in the program's
rules list after validation.

# `compute_strata`

```elixir
@spec compute_strata(ExDatalog.Program.t()) :: [ExDatalog.IR.Stratum.t()]
```

Computes stratum structures for the IR.

Returns a list of `ExDatalog.IR.Stratum` structs, one per distinct stratum,
ordered by stratum index. Each stratum contains the rule IDs and relation
names that belong to it.

EDB-only relations (no rules defining them) are always in stratum 0.

---

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