Struct sorting_visualization::state::State[][src]

pub struct State {
    pub time: f64,
    pub speed: f64,
    pub paused: bool,
    pub array: Vec<u32>,
    pub colors: Vec<Color>,
    pub array_accesses: Vec<f64>,
}

Contains the state of the whole app.

Fields

time: f64

Current time in seconds. Updated if the animation is not paused.

speed: f64

Speed factor (e.g. 1.0 - normal, 2.0 - 2x faster, 0.5 - 2x slower, etc). Affects the animation time and delays in algorithms.

paused: bool

Is the animation paused?

array: Vec<u32>

An array which is being sorted.

colors: Vec<Color>

Colored overlays of each value. Overlay means that these colors are not used to draw the values, instead they’re drawn over the values. These colors can be used by an algorithm to highlight important array elements.

The length of this vector is equal to the array length, so every color in this vector corresponds to a value with the exact same index.

array_accesses: Vec<f64>

Contains timestamps of the most recent array accesses of every element, which are drawn like colored overlays. The length of this vector is equal to the array length, so for every element in the array only the most recent timestamp is stored here (not a big deal), so we can avoid memory allocations while program is running, and this is a pretty simple optimization. To optimize things even further I’ve done this: if an element hasn’t been accessed yet or it has been accessed long ago, then instead of using an Option<f64> type for every element, I use negative values because they don’t make any sense in the context of time (this saves 8 bytes for every element). When an algorithm reads or writes a value at a certain index from/to the array, the current time is stored at exactly the same index in this vector.

Trait Implementations

impl Debug for State[src]

Auto Trait Implementations

impl RefUnwindSafe for State

impl Send for State

impl Sync for State

impl Unpin for State

impl UnwindSafe for State

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SetParameter for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.