pub struct FractionAvg { /* private fields */ }Expand description
A simple fraction struct that allows adding numbers to the numerator and denominator
If we want compute a rolling-average, we would naively hold all elements in a list and compute the average from it. This is not efficient, as it requires O(n) memory and O(n) time to compute the average. Instead, we can use a fraction to compute the average in O(1) time and O(1) memory, by keeping track of the sum of all elements and the number of elements.
Implementations§
Source§impl FractionAvg
impl FractionAvg
Trait Implementations§
Source§impl Clone for FractionAvg
impl Clone for FractionAvg
Source§fn clone(&self) -> FractionAvg
fn clone(&self) -> FractionAvg
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FractionAvg
impl RefUnwindSafe for FractionAvg
impl Send for FractionAvg
impl Sync for FractionAvg
impl Unpin for FractionAvg
impl UnwindSafe for FractionAvg
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