Struct strider::SliceRingImpl [] [src]

pub struct SliceRingImpl<T> {
    pub first_readable: usize,
    pub next_writable: usize,
    pub buf: Vec<T>,
}

readable area starts at first_readable and goes until next_writable. next_writable is one after the last readable and not readable.

R = first_readable
W = next_writable
o = occupied (len)
. = free

 R             W
[o o o o o o o . . . .]

Fields

first_readable

index into buf of the first element that could be read. only gets incremented, never decremented. wraps around.

next_writable

index into buf where the next element could we written. only gets incremented, never decremented. wraps around at buf.cap().

buf

Methods

impl<T> SliceRingImpl<T>

ringbuffer focused on and optimized for operating on slices of values: appending to the back, reading from the front and dropping from the front. which is much faster. TODO call SliceRingImplImpl

fn new() -> SliceRingImpl<T>

creates an empty SliceRingImpl.

fn with_capacity(n: usize) -> SliceRingImpl<T>

creates an empty SliceRingImpl with space for at least n elements.

fn cap(&self) -> usize

fn capacity(&self) -> usize

fn is_continuous(&self) -> bool

fn len(&self) -> usize

returns the number of elements in the SliceRingImpl

fn wrap_add(&self, index: usize, addend: usize) -> usize

returns the index into the underlying buffer for a given logical element index + addend

unsafe fn handle_cap_increase(&mut self, old_cap: usize)

this is the most complex part Frobs the head and tail sections around to handle the fact that we just reallocated. Unsafe because it trusts old_cap.

Trait Implementations

impl<T: Clone> SliceRing<T> for SliceRingImpl<T>

fn push_many_back(&mut self, input: &[T])

fn drop_many_front(&mut self, count: usize) -> usize

fn read_many_front(&self, output: &mut [T]) -> usize