# `ExDataSketch.Binary.CRC`
[🔗](https://github.com/thanos/ex_data_sketch/blob/main/lib/ex_data_sketch/binary/crc.ex#L1)

CRC32C (Castagnoli polynomial, reflected, init 0xFFFFFFFF, xor-out
0xFFFFFFFF) — the checksum used by EXSK v2 frames.

CRC32C is the same checksum used by iSCSI, Btrfs, SCTP, and many storage
systems. It is hardware-accelerated by Intel SSE 4.2 (`CRC32` instruction)
and ARMv8.1+ (`CRC32CB/CRC32CH/CRC32CW/CRC32CX`), so the Rust NIF version
is essentially free on modern hardware.

## Polynomial

    Reversed polynomial: 0x82F63B78 (Castagnoli reflected)
    Init value:          0xFFFFFFFF
    Final xor:           0xFFFFFFFF
    Reflect input/output: true

## Stability

The CRC32C function is a well-specified standard. Output is identical
across every implementation. The pure Elixir implementation and the
Rust NIF implementation are property-tested for byte-identical agreement
on random inputs.

## Examples

    iex> ExDataSketch.Binary.CRC.crc32c(<<>>)
    0

    iex> ExDataSketch.Binary.CRC.crc32c("123456789")
    0xE3069283

# `check_vector`

```elixir
@spec check_vector() :: {binary(), non_neg_integer()}
```

Returns the standard CRC32C check vector ("123456789" -> 0xE3069283).

This vector is published by the CRC reference catalogue and matches every
CRC32C implementation (iSCSI, Btrfs, SCTP, hardware CRC32 instruction).

## Examples

    iex> ExDataSketch.Binary.CRC.check_vector()
    {"123456789", 0xE3069283}

# `crc32c`

```elixir
@spec crc32c(binary()) :: non_neg_integer()
```

Computes the CRC32C of the given binary.

Dispatches to the Rust NIF when available, falling back to a pure-Elixir
table-driven implementation otherwise. Both implementations produce
byte-identical output.

## Examples

    iex> ExDataSketch.Binary.CRC.crc32c(<<>>)
    0

    iex> ExDataSketch.Binary.CRC.crc32c("hello")
    0x9A71BB4C

# `pure_crc32c`

```elixir
@spec pure_crc32c(binary()) :: non_neg_integer()
```

Pure-Elixir CRC32C implementation. Never calls the NIF.

Provided for parity testing and as the BEAM-only fallback.

## Examples

    iex> ExDataSketch.Binary.CRC.pure_crc32c("123456789")
    0xE3069283

---

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