# `Localize.Collation.SortKey`
[🔗](https://github.com/elixir-localize/localize/blob/v0.38.0/lib/localize/collation/sort_key.ex#L1)

Constructs binary sort keys from processed collation elements.

Sort keys are multi-level byte sequences that can be compared with
binary comparison (`<`, `>`, `==`) to determine string ordering.

Structure: [L1 weights] 0000 [L2 weights] 0000 [L3 weights] [0000 L4 weights]

# `build`

```elixir
@spec build(
  [{Localize.Collation.Element.t(), non_neg_integer()}],
  Localize.Collation.Options.t(),
  String.t() | nil
) :: binary()
```

Build a binary sort key from processed collation elements.

### Arguments

* `processed_elements` - a list of `{element, quaternary}` tuples as returned
  by `Localize.Collation.Variable.process/3`.

* `options` - a `%Localize.Collation.Options{}` struct controlling which levels
  to include.

* `original_string` - the original input string, used for the identical level
  (default: `nil`).

### Returns

A binary sort key where levels are separated by `<<0x00, 0x00>>`.

### Examples

    iex> elements = [{{0x23EC, 0x0020, 0x0008, false}, 0}]
    iex> options = Localize.Collation.Options.new(strength: :primary)
    iex> Localize.Collation.SortKey.build(elements, options)
    <<0x23, 0xEC>>

---

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