[−][src]Struct bit_mask_ring_buf::BitMaskRingBuf
A fast ring buffer implementation with cheap and safe indexing. It works by bit-masking
an integer index to get the corresponding index in an array/vec whose length
is a power of 2. This is best used when indexing the buffer with an isize
value.
Copies/reads with slices are implemented with memcpy.
Implementations
impl<T: Copy + Clone + Default> BitMaskRingBuf<T>
[src]
pub fn from_capacity(capacity: usize) -> Self
[src]
Creates a new BitMaskRingBuf
with a capacity that is at least the given
capacity. The buffer will be initialized with the default value.
capacity
- The capacity of the ring buffer. The actual capacity will be set to the next highest power of 2 ifcapacity
is not already a power of 2.
pub fn from_ms(milliseconds: f64, sample_rate: f64) -> Self
[src]
Creates a new BitMaskRingBuf
with a capacity that holds at least a number of
frames/samples in a given time peroid. The actual capacity will be set to the
lowest power of 2 that can hold that many values.
The buffer will be initialized with the default value.
milliseconds
- The time period in milliseconds.sample_rate
- The sample rate in samples per second.
Panics
- This will panic if either
milliseconds
orsample_rate
is less than 0.
pub fn set_capacity(&mut self, capacity: usize)
[src]
Sets the capacity of the ring buffer. The actual capacity will be set
to the next highest power of 2 if capacity
is not already a power of 2.
This will also clear all values to the default value.
pub fn set_capacity_from_ms(&mut self, milliseconds: f64, sample_rate: f64)
[src]
Creates a new BitMaskRingBuf
with a capacity that holds at least a number of
frames/samples in a given time peroid. The actual capacity will be set to the
lowest power of 2 that can hold that many values.
This will also clear all values to the default value.
milliseconds
- The time period in milliseconds.sample_rate
- The sample rate in samples per second.
Panics
- This will panic if either
milliseconds
orsample_rate
is less than 0.
pub fn clear(&mut self)
[src]
Clears all values in the ring buffer to the default value.
pub fn as_slices(&self, start: isize) -> (&[T], &[T])
[src]
Returns two slices that contain the all the data in the ring buffer
starting at the index start
.
Returns
- The first slice is the starting chunk of data. This will never be empty.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
pub fn as_slices_len(&self, start: isize, len: usize) -> (&[T], &[T])
[src]
Returns two slices of data in the ring buffer
starting at the index start
and with length len
.
start
- The starting indexlen
- The length of data to read. Iflen
is greater than the capacity of the ring buffer, then that capacity will be used instead.
Returns
- The first slice is the starting chunk of data.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
pub fn as_mut_slices(&mut self, start: isize) -> (&mut [T], &mut [T])
[src]
Returns two mutable slices that contain the all the data in the ring buffer
starting at the index start
.
Returns
- The first slice is the starting chunk of data. This will never be empty.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
pub fn as_mut_slices_len(
&mut self,
start: isize,
len: usize
) -> (&mut [T], &mut [T])
[src]
&mut self,
start: isize,
len: usize
) -> (&mut [T], &mut [T])
Returns two mutable slices of data in the ring buffer
starting at the index start
and with length len
.
start
- The starting indexlen
- The length of data to read. Iflen
is greater than the capacity of the ring buffer, then that capacity will be used instead.
Returns
- The first slice is the starting chunk of data.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
pub fn read_into(&self, slice: &mut [T], start: isize)
[src]
Copies the data from the ring buffer starting from the index start
into the given slice. If the length of slice
is larger than the
capacity of the ring buffer, then the data will be reapeated until
the given slice is filled.
slice
- This slice to copy the data into.start
- The index of the ring buffer to start copying from.
pub fn write_latest(&mut self, slice: &[T], start: isize)
[src]
Copies data from the given slice into the ring buffer starting from
the index start
. If the length of slice
is larger than the
capacity of the ring buffer, then only the latest data will be copied.
slice
- This slice to copy data from.start
- The index of the ring buffer to start copying from.
pub fn capacity(&self) -> usize
[src]
Returns the capacity of the ring buffer.
pub fn constrain(&self, i: isize) -> isize
[src]
Returns the actual index of the ring buffer from the given
i
index. This is cheap due to the ring buffer's bit-masking
algorithm.
Trait Implementations
impl<T: Copy + Clone + Default> Index<isize> for BitMaskRingBuf<T>
[src]
impl<T: Copy + Clone + Default> IndexMut<isize> for BitMaskRingBuf<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for BitMaskRingBuf<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for BitMaskRingBuf<T> where
T: Send,
T: Send,
impl<T> Sync for BitMaskRingBuf<T> where
T: Sync,
T: Sync,
impl<T> Unpin for BitMaskRingBuf<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for BitMaskRingBuf<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,