Skip to main content

SnapshotTable

Struct SnapshotTable 

Source
pub struct SnapshotTable {
    pub snapshots: Vec<Snapshot>,
    pub diffs: Vec<DiffEntry>,
    pub compressed: HashMap<String, Vec<(f64, usize)>>,
}
Expand description

Time-indexed table of simulation snapshots with optional RLE compression and differential storage.

Fields§

§snapshots: Vec<Snapshot>

Stored snapshots ordered by insertion time.

§diffs: Vec<DiffEntry>

Differential entries for fields that change sparsely between snapshots.

§compressed: HashMap<String, Vec<(f64, usize)>>

RLE-compressed versions of field arrays, keyed by "field@time_idx".

Implementations§

Source§

impl SnapshotTable

Source

pub fn new() -> Self

Create an empty table.

Source

pub fn insert(&mut self, snap: Snapshot)

Insert a snapshot; snapshots are kept in ascending time order.

Source

pub fn query_time_range(&self, t_lo: f64, t_hi: f64) -> Vec<&Snapshot>

Return all snapshots whose time falls in \[t_lo, t_hi\].

Source

pub fn nearest(&self, t: f64) -> Option<&Snapshot>

Retrieve a single snapshot whose time is closest to t.

Source

pub fn compress_field(&mut self, snap_idx: usize, field: &str)

Compress a named field of the snapshot at index snap_idx using RLE.

The compressed data is stored internally under the key "field@snap_idx".

Source

pub fn decompress_field(&self, snap_idx: usize, field: &str) -> Option<Vec<f64>>

Decompress a previously compressed field, returning the flat Vecf64`.

Returns None if the field was not compressed.

Source

pub fn compute_diff(&mut self, field: &str, snap_idx: usize) -> usize

Compute the differential between consecutive snapshots for a named field and store the result in self.diffs.

Returns the number of changed elements.

Source

pub fn apply_diff(base: &mut [f64], diff: &DiffEntry)

Apply a stored diff to a base field array, returning the updated array.

base is modified in-place by overwriting the changed indices.

Source

pub fn len(&self) -> usize

Return the number of snapshots.

Source

pub fn is_empty(&self) -> bool

Return true if the table is empty.

Trait Implementations§

Source§

impl Debug for SnapshotTable

Source§

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

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

impl Default for SnapshotTable

Source§

fn default() -> SnapshotTable

Returns the “default value” for a type. 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.