Uniform

Struct Uniform 

Source
pub struct Uniform { /* private fields */ }
Expand description

The struct representing an uniform distribution.

Given a range, it generates a vector of uniform distributed input sizes.

Implementations§

Source§

impl Uniform

Source

pub fn new(range: RangeInclusive<usize>) -> Self

Creates a new uniform distribution.

§Arguments
  • range - The range of the distribution.
Examples found in repository?
examples/search/main.rs (line 22)
19fn main() {
20    // Create a distribution for the length of the vectors
21    // Here we use an uniform distribution with a minimum of 10 and a maximum of 100_000
22    let length_distribution = Uniform::new(10..=100_000);
23
24    // Create the builder for the vectors
25    // Here we choose to use the fast generator method in order to generate ordered vectors
26    let vector_builder = InputBuilder::new(length_distribution, Generator::Fast);
27
28    // Build 200 vectors
29    let vectors = vector_builder.build(200);
30
31    // Create a slice of the algorithms we want to measure
32    let algorithms: &[(fn(&input::SearchInput) -> Option<usize>, &str); 2] = &[
33        (linear_search_input, "Linear search"),
34        (binary_search_input, "Binary search"),
35    ];
36
37    // Measure the algorithms on the vectors, given a relative error of 0.001
38    let results = measure(&vectors, algorithms, 0.001);
39
40    let file_name = "results/search.svg";
41
42    // Here we print the linear regression of the log-log scale of the results
43    for result in results.clone().measurements {
44        let log_linear_regression = result.log_log_scale().linear_regression();
45        println!(
46            "{}: {} * x + {}",
47            result.algorithm_name, log_linear_regression.0, log_linear_regression.1
48        )
49    }
50
51    let config = PlotConfig::default()
52        .with_title("Search in an ordered vector")
53        .with_caption("The time plot of searching algorithms in an ordered vector");
54
55    // Plot the results
56    time_plot(file_name, results, &config);
57}
Source

pub fn set_gen_type(&mut self, gen_type: GenerationType)

Sets the generation type of the exponential distribution. The generation type can be either fixed intervals or random.

§Arguments
  • gen_type - The generation type.

Trait Implementations§

Source§

impl Clone for Uniform

Source§

fn clone(&self) -> Uniform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Uniform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ProbabilityDistribution for Uniform

Source§

fn inverse_cdf(&self, u: f64) -> f64

This function takes a value x in [0,1] uniformly distributed and returns a value that is distributed according to the probability distribution chosen. Read more
Source§

fn get_gen_type(&self) -> &GenerationType

Returns the generation type of the distribution. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Distribution for T

Source§

fn generate(&self, n: usize) -> Vec<usize>

Generates a vector of input sizes. The number of input sizes to generate is given as argument.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V