#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub struct CostConstants {
memory_block_read_cost: f64,
io_block_read_cost: f64,
}
impl CostConstants {
#[must_use]
pub const fn new(memory_block_read_cost: f64, io_block_read_cost: f64) -> Self {
Self {
memory_block_read_cost,
io_block_read_cost,
}
}
#[must_use]
pub const fn defaults() -> Self {
Self::new(0.25, 1.0)
}
#[must_use]
pub const fn memory_block_read_cost(&self) -> f64 {
self.memory_block_read_cost
}
#[must_use]
pub const fn io_block_read_cost(&self) -> f64 {
self.io_block_read_cost
}
}
impl Default for CostConstants {
fn default() -> Self {
Self::defaults()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_match_se_cost_constants_original() {
let c = CostConstants::defaults();
assert!((c.memory_block_read_cost() - 0.25).abs() < f64::EPSILON);
assert!((c.io_block_read_cost() - 1.0).abs() < f64::EPSILON);
}
#[test]
fn new_preserves_values() {
let c = CostConstants::new(0.5, 2.5);
assert!((c.memory_block_read_cost() - 0.5).abs() < f64::EPSILON);
assert!((c.io_block_read_cost() - 2.5).abs() < f64::EPSILON);
}
}