pub struct Context<'a, Fe, R, C> {
fitness: &'a Fe,
rng: &'a mut R,
comparator: &'a C,
#[cfg(feature = "parallel")]
runtime: &'a pooled::Runtime,
}
impl<'a, Fe, R, C> Context<'a, Fe, R, C> {
#[cfg(not(feature = "parallel"))]
pub fn new(fitness: &'a Fe, rng: &'a mut R, comparator: &'a C) -> Self {
Self {
fitness,
rng,
comparator,
}
}
#[cfg(feature = "parallel")]
pub fn new(
fitness: &'a Fe,
rng: &'a mut R,
comparator: &'a C,
runtime: &'a pooled::Runtime,
) -> Self {
Self {
fitness,
rng,
comparator,
runtime,
}
}
pub fn fitness_evaluator(&self) -> &Fe {
self.fitness
}
pub fn rng(&mut self) -> &mut R {
self.rng
}
pub fn comparator(&self) -> &C {
self.comparator
}
#[cfg(feature = "parallel")]
pub fn pool(&self) -> pooled::map::MapPool<'_> {
self.runtime.map_pool()
}
#[cfg(feature = "parallel")]
pub fn runtime(&self) -> &pooled::Runtime {
self.runtime
}
}