pub struct SliceView<'a, V> { /* private fields */ }Expand description
A borrowed slice start..end of a sequence that is not copied, for
reducing many slices cheaply. Positions are relative to start.
use runlength::{Rle, RleLike};
let rle = Rle::from_runs(&[3, 2, 4], vec![1, 5, 2]).unwrap();
let view = rle.slice_view(2, 6);
assert_eq!(view.len(), 4);
assert_eq!(view.sum(), 1 + 5 + 5 + 2);
assert_eq!(view.to_rle().to_dense(), vec![1, 5, 5, 2]);Implementations§
Source§impl<'a, V> SliceView<'a, V>
impl<'a, V> SliceView<'a, V>
pub fn is_empty(&self) -> bool
Sourcepub fn iter_runs(&self) -> impl Iterator<Item = (i64, i64, &'a V)> + Clone + 'a
pub fn iter_runs(&self) -> impl Iterator<Item = (i64, i64, &'a V)> + Clone + 'a
Iterates over (start, end, value) for each run, relative to the
start of the slice.
Sourcepub fn to_rle(&self) -> Rle<V>where
V: Clone,
pub fn to_rle(&self) -> Rle<V>where
V: Clone,
Copies the slice into an owned sequence starting at 0.
Sourcepub fn mean(&self) -> Option<f64>where
V: Num,
pub fn mean(&self) -> Option<f64>where
V: Num,
The mean over all positions, or None if the slice is empty.
Sourcepub fn variance(&self, ddof: i64) -> Option<f64>where
V: Num,
pub fn variance(&self, ddof: i64) -> Option<f64>where
V: Num,
The variance with ddof delta degrees of freedom, or None if
len() <= ddof.
Sourcepub fn min(&self) -> Option<&'a V>where
V: PartialOrd,
pub fn min(&self) -> Option<&'a V>where
V: PartialOrd,
The smallest value, ignoring values not comparable with themselves.
Sourcepub fn max(&self) -> Option<&'a V>where
V: PartialOrd,
pub fn max(&self) -> Option<&'a V>where
V: PartialOrd,
The largest value, ignoring values not comparable with themselves.
Trait Implementations§
Auto Trait Implementations§
impl<'a, V> Freeze for SliceView<'a, V>
impl<'a, V> RefUnwindSafe for SliceView<'a, V>where
&'a [V]: RefUnwindSafe,
impl<'a, V> Send for SliceView<'a, V>
impl<'a, V> Sync for SliceView<'a, V>
impl<'a, V> Unpin for SliceView<'a, V>
impl<'a, V> UnsafeUnpin for SliceView<'a, V>where
&'a [V]: UnsafeUnpin,
impl<'a, V> UnwindSafe for SliceView<'a, V>where
&'a [V]: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more