# `ExVrp.RingBuffer`
[🔗](https://github.com/sephianl/ex_vrp/blob/v0.4.2/lib/ex_vrp/ring_buffer.ex#L1)

A fixed-size circular buffer for tracking recently inserted values.

The ring buffer stores up to `maxlen` items. When full, new items
overwrite the oldest ones. The `peek/1` function returns the value
that would be overwritten by the next append, or `nil` if that slot
hasn't been written yet.

## Example

    buffer = ExVrp.RingBuffer.new(2)
    buffer = ExVrp.RingBuffer.append(buffer, :a)
    buffer = ExVrp.RingBuffer.append(buffer, :b)
    ExVrp.RingBuffer.peek(buffer)  # => :a (next to be overwritten)

# `t`

```elixir
@type t() :: %ExVrp.RingBuffer{
  buffer: list(),
  head: non_neg_integer(),
  maxlen: pos_integer(),
  size: non_neg_integer()
}
```

# `append`

```elixir
@spec append(t(), term()) :: t()
```

Appends a value to the buffer.

If the buffer is full, the oldest value is overwritten.

# `clear`

```elixir
@spec clear(t()) :: t()
```

Clears the buffer, resetting it to its initial state.

# `length`

```elixir
@spec length(t()) :: non_neg_integer()
```

Returns the current number of items in the buffer.

# `maxlen`

```elixir
@spec maxlen(t()) :: pos_integer()
```

Returns the maximum length of the buffer.

# `new`

```elixir
@spec new(pos_integer()) :: t()
```

Creates a new ring buffer with the given maximum length.

## Example

    buffer = ExVrp.RingBuffer.new(3)

# `peek`

```elixir
@spec peek(t()) :: term() | nil
```

Peeks at the value in the next slot (the one that would be overwritten next).

Returns `nil` if that slot hasn't been written to yet.

# `skip`

```elixir
@spec skip(t()) :: t()
```

Skips to the next slot without writing anything.

This moves the head pointer forward without changing the size.

---

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