# Crate timestamp_stretcher[−][src]

Expand description

# `TimeStretcher`

Stretch integer (`u64`) time stamps by a fractional factor that may change over time.

## Examples

The following example illustrates the usage of the library.

```use timestamp_stretcher::TimestampStretcher;
use std::num::NonZeroU64;

// Create a new TimeStretcher with an initial factor of 2/3.
let mut stretcher = TimestampStretcher::new(2, NonZeroU64::new(3).unwrap());

// Suppose we have five events: "0", "1", "2", "3" and "4".
// Each event happens at a certain time stamp:
//       +--- Time stamp of event "1" is 3
//       v
// 0 . . 1 . . 2 . . . . 3 . . . . 4
// If we stretch the time stamps up to event 2 with a factor 2/3,
// and the subsequent time stamps with a factor 7/5, we get the following:
// 0 . 1 . 2 . . . . . . 3 . . . . . . 4
let input_time_stamps = vec![
(0, None),                                     // Event at time 0, no change to conversion factor.
(3, None),                                     // Event at time 3, no change to conversion factor.
(6, Some((7, NonZeroU64::new(5).unwrap()))),   // Event at time 6, change conversion factor to 7/8.
// The new conversion factor will be applied to the time differences, not to the absolute times.
(11, None),                                    // Event at time 11.
(16, None),
];
let mut observed_output_time_stamps = Vec::new();
for input in input_time_stamps.into_iter() {
observed_output_time_stamps.push(stretcher.stretch(input.0, input.1));
}
let expected_output_time_stamps = vec![0, 2, 4, 11, 18];
assert_eq!(expected_output_time_stamps, observed_output_time_stamps);```

## Structs

Stretch integer (`u64`) time stamps by a fractional factor that may change over time.