Skip to main content

MemoryStorage

Struct MemoryStorage 

Source
pub struct MemoryStorage<V> { /* private fields */ }
Expand description

In-memory trial storage (the default).

Wrap a Vec<CompletedTrial<V>> behind a read-write lock so that trials can be appended from any thread. This is the backend that Study uses when no explicit storage is provided.

Use with_trials to seed a study with previously collected data.

§Example

use optimizer::storage::{MemoryStorage, Storage};

let storage = MemoryStorage::<f64>::new();
assert_eq!(storage.trials_arc().read().len(), 0);

Implementations§

Source§

impl<V> MemoryStorage<V>

Source

pub fn new() -> Self

Create a new, empty in-memory store.

Source

pub fn with_trials(trials: Vec<CompletedTrial<V>>) -> Self

Create an in-memory store pre-populated with trials.

The internal ID counter is set to one past the highest trial ID so that subsequent trials receive unique IDs.

Trait Implementations§

Source§

impl<V> Default for MemoryStorage<V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<V: Send + Sync> Storage<V> for MemoryStorage<V>

Source§

fn push(&self, trial: CompletedTrial<V>)

Append a completed trial to the store.
Source§

fn trials_arc(&self) -> &Arc<RwLock<Vec<CompletedTrial<V>>>>

Return a reference to the in-memory trial buffer. Read more
Source§

fn next_trial_id(&self) -> u64

Atomically return the next unique trial ID. Read more
Source§

fn peek_next_trial_id(&self) -> u64

Return the current value of the next-trial-ID counter without incrementing. Read more
Source§

fn refresh(&self) -> bool

Reload from an external source (e.g. a file written by another process). Return true if the in-memory buffer was updated. Read more

Auto Trait Implementations§

§

impl<V> !Freeze for MemoryStorage<V>

§

impl<V> !RefUnwindSafe for MemoryStorage<V>

§

impl<V> Send for MemoryStorage<V>
where V: Send + Sync,

§

impl<V> Sync for MemoryStorage<V>
where V: Send + Sync,

§

impl<V> Unpin for MemoryStorage<V>

§

impl<V> !UnwindSafe for MemoryStorage<V>

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, 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.