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: usize
index into buf
of the first element that could be read.
only gets incremented, never decremented.
wraps around.
next_writable: usize
index into buf
where the next element could we written.
only gets incremented, never decremented.
wraps around at buf.cap()
.
buf: Vec<T>
Methods
impl<T> SliceRingImpl<T>
[src]
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>
[src]
fn push_many_back(&mut self, input: &[T])
appends values
to the back of this ring.
fn drop_many_front(&mut self, count: usize) -> usize
removes count
elements from the front of this ring. returns how many elements were removed. returns less than count
if less elements are present in this ring. Read more
fn read_many_front(&self, output: &mut [T]) -> usize
copies the first output.len()
elements present in this ring into output
. returns how many elements were copied. returns less than output.len()
if there are less elements present in this ring. Read more