# `Juggernaut.MutantId`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/mutant_id.ex#L1)

Canonical mutant keys and short ids (design notes §6).

The key names a mutant by where it is inside its function clause and what it changes,
never by line number, so an edit outside the clause keeps it:

    <Module>|<fun>/<arity>|c<clause>|p<path>|<operator>:<variant>|r<rhash>
    Elixir.MyApp.Approvals.Grant|check/2|c1|p2.0.1|relational:>=|r3fa9c1d2e4b5

The short id shown everywhere is `<Alias>.<fun>/<arity>:<operator>:<h7>`, where `h7` is
the first 7 hex digits of the key's SHA-256. When two mutants of a run share those
digits, each of them gets one more digit until they differ.

# `parts`

```elixir
@type parts() :: %{
  module: module(),
  function: {atom(), arity()},
  clause: non_neg_integer(),
  path: [non_neg_integer()],
  operator: atom(),
  variant: String.t() | nil,
  replacement: String.t()
}
```

# `find`

```elixir
@spec find([%{id: String.t(), key: String.t()}], String.t()) ::
  {:ok, map()} | {:error, :unknown} | {:error, {:ambiguous, [String.t()]}}
```

Finds the one mutant `query` names among `mutants` (anything with `:id` and `:key`): a
full short id, a canonical key, its hash part, or a unique prefix of the hash part of 4
or more characters (hash parts are hex, so anything else names nothing).

# `hash_part`

```elixir
@spec hash_part(String.t()) :: String.t()
```

The hash part of a short id (after the last `:`).

# `key`

```elixir
@spec key(parts()) :: String.t()
```

The canonical key of a mutant.

# `rhash`

```elixir
@spec rhash(String.t()) :: String.t()
```

The first 12 hex digits of the SHA-256 of a rendered replacement.

# `short_ids`

```elixir
@spec short_ids([{String.t(), module(), {atom(), arity()}, atom()}], pos_integer()) ::
  %{
    required(String.t()) =&gt; String.t()
  }
```

Short ids for `entries` (`{key, module, function, operator}`), as a map from key to id.
Deterministic: the same set of keys always gets the same ids. `digits` (default 7) is
the shortest hash part.

---

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