pub fn update(&mut self, sample: &Sample) -> Result<Option<(f64, u32)>, FrequencyUpdateError> {
        match self.current_window.add_sample(sample) {
            Ok(()) => {
                // This sample was accepted into the current window so didn't lead to a
                // frequency change.
                Ok(None)
            }
            Err(AddSampleError::BeforeWindow) => {
                // If the server had a large step back in time theoretically we might see a UTC
                // before the window we were accumulating into, in that case just start over.
                self.current_window = EstimationWindow::new(sample);
                Err(FrequencyUpdateError::UtcBeforeWindow)
            }
            Err(AddSampleError::AfterWindow) => {
                // This sample was after the current window. Start a new window and if the previous
                // window was viable use its data.
                let previous_window =
                    mem::replace(&mut self.current_window, EstimationWindow::new(sample));
                match previous_window.frequency() {
                    Ok(window_estimate) => {
                        if self.window_count == 0 {
                            // If this is the first window use the estimated frequency directly...
                            self.estimate = window_estimate;
                        } else {
                            // ... otherwise combine it with the previous estimate.
                            self.estimate = window_estimate * FREQUENCY_ESTIMATION_SMOOTHING
                                + self.estimate * (1f64 - FREQUENCY_ESTIMATION_SMOOTHING);
                        }
                        self.window_count += 1;
                        Ok(Some((self.estimate, self.window_count)))
                    }
                    Err(err) => Err(err.into()),
                }
            }
        }
    }
/// Update the estimate to include the supplied sample. Very occasionally this will lead to a
/// change in the estimated frequency, in which case the new frequency and the total number of
/// windows used in producing this new frequency are returned.
Update the estimate to include the supplied sample. Very occasionally this will lead to a
change in the estimated frequency, in which case the new frequency and the total number of
windows used in producing this new frequency are returned.
Update the estimate to include the supplied sample . Very occasionally this will lead to a change in the estimated frequency in which case the new frequency and the total number of windows used in producing this new frequency are returned .
pub fn update(&mut self, sample: &Sample) -> Result<Option<(f64, u32)>, FrequencyUpdateError> {
        match self.current_window.add_sample(sample) {
            Ok(()) => {
                // This sample was accepted into the current window so didn't lead to a
                // frequency change.
                Ok(None)
            }
            Err(AddSampleError::BeforeWindow) => {
                // If the server had a large step back in time theoretically we might see a UTC
                // before the window we were accumulating into, in that case just start over.
                self.current_window = EstimationWindow::new(sample);
                Err(FrequencyUpdateError::UtcBeforeWindow)
            }
            Err(AddSampleError::AfterWindow) => {
                // This sample was after the current window. Start a new window and if the previous
                // window was viable use its data.
                let previous_window =
                    mem::replace(&mut self.current_window, EstimationWindow::new(sample));
                match previous_window.frequency() {
                    Ok(window_estimate) => {
                        if self.window_count == 0 {
                            // If this is the first window use the estimated frequency directly...
                            self.estimate = window_estimate;
                        } else {
                            // ... otherwise combine it with the previous estimate.
                            self.estimate = window_estimate * FREQUENCY_ESTIMATION_SMOOTHING
                                + self.estimate * (1f64 - FREQUENCY_ESTIMATION_SMOOTHING);
                        }
                        self.window_count += 1;
                        Ok(Some((self.estimate, self.window_count)))
                    }
                    Err(err) => Err(err.into()),
                }
            }
        }
    }
pub fn update ( & mut self , sample : & Sample ) -> Result < Option < ( f64 , u32 ) > , FrequencyUpdateError > { match self . current_window . add_sample ( sample ) { Ok ( ( ) ) => { // This sample was accepted into the current window so didn't lead to a // frequency change. Ok ( None ) } Err ( AddSampleError :: BeforeWindow ) => { // If the server had a large step back in time theoretically we might see a UTC // before the window we were accumulating into, in that case just start over. self . current_window = EstimationWindow :: new ( sample ) ; Err ( FrequencyUpdateError :: UtcBeforeWindow ) } Err ( AddSampleError :: AfterWindow ) => { // This sample was after the current window. Start a new window and if the previous // window was viable use its data. let previous_window = mem :: replace ( & mut self . current_window , EstimationWindow :: new ( sample ) ) ; match previous_window . frequency ( ) { Ok ( window_estimate ) => { if self . window_count == 0 { // If this is the first window use the estimated frequency directly... self . estimate = window_estimate ; } else { // ... otherwise combine it with the previous estimate. self . estimate = window_estimate * FREQUENCY_ESTIMATION_SMOOTHING + self . estimate * ( 1f64 - FREQUENCY_ESTIMATION_SMOOTHING ) ; } self . window_count += 1 ; Ok ( Some ( ( self . estimate , self . window_count ) ) ) } Err ( err ) => Err ( err . into ( ) ) , } } } }
Update the estimate to include the supplied sample.
Update the estimate to include the supplied sample .
&mut self
sample
&Sample
&mut self
sample
&Sample