pub struct SliceRingImpl<T> {
pub first_readable: usize,
pub next_writable: usize,
pub buf: Vec<T>,
}
Expand description
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>
Implementations§
Source§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
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
Sourcepub fn new() -> SliceRingImpl<T>
pub fn new() -> SliceRingImpl<T>
creates an empty SliceRingImpl
.
Sourcepub fn with_capacity(n: usize) -> SliceRingImpl<T>
pub fn with_capacity(n: usize) -> SliceRingImpl<T>
creates an empty SliceRingImpl
with space for at least n
elements.
pub fn cap(&self) -> usize
pub fn capacity(&self) -> usize
pub fn is_continuous(&self) -> bool
Sourcepub fn wrap_add(&self, index: usize, addend: usize) -> usize
pub fn wrap_add(&self, index: usize, addend: usize) -> usize
returns the index into the underlying buffer for a given logical element index + addend
Sourcepub unsafe fn handle_cap_increase(&mut self, old_cap: usize)
pub 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§
Source§impl<T: Clone> SliceRing<T> for SliceRingImpl<T>
impl<T: Clone> SliceRing<T> for SliceRingImpl<T>
Source§fn push_many_back(&mut self, input: &[T])
fn push_many_back(&mut self, input: &[T])
values
to the back of this ring.Source§fn drop_many_front(&mut self, count: usize) -> usize
fn drop_many_front(&mut self, count: usize) -> usize
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.Source§fn read_many_front(&self, output: &mut [T]) -> usize
fn read_many_front(&self, output: &mut [T]) -> usize
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.