RingBuffer

class RingBuffer<T>(val capacity: Int)

A highly efficient, fixed-capacity circular buffer. Used to store the terminal scrollback history without requiring O(N) array shifting when the history exceeds its maximum capacity.

Parameters

T

The type of elements stored in the buffer.

Constructors

Link copied to clipboard
constructor(capacity: Int)

Properties

Link copied to clipboard

The maximum number of elements this buffer can hold.

Link copied to clipboard
var size: Int

The current number of elements stored in the buffer.

Functions

Link copied to clipboard
fun clear()

Clears all elements from the buffer and resets its state.

Link copied to clipboard
fun get(index: Int): T

Retrieves an item at the specified logical index. Index 0 represents the oldest element in the buffer.

Link copied to clipboard
fun push(item: T)

Pushes a new item into the buffer. If the buffer is full, the oldest item is overwritten.