use std::time::SystemTime;
use sciparse::path::ScionPath;
use crate::path::manager::reliability::ReliabilityScore;
#[derive(Debug)]
pub(crate) struct PathManagerPath {
pub path: ScionPath,
pub reliability: ReliabilityScore,
}
impl PathManagerPath {
pub fn new(path: ScionPath) -> Self {
Self {
path,
reliability: ReliabilityScore::new_with_time(SystemTime::now()),
}
}
pub fn scion_path(&self) -> &ScionPath {
&self.path
}
}
impl From<&ScionPath> for PathManagerPath {
fn from(path: &ScionPath) -> Self {
Self::new(path.clone())
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) struct Score(f32);
impl Eq for Score {}
impl Ord for Score {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0
.partial_cmp(&other.0)
.unwrap_or(std::cmp::Ordering::Equal)
}
}
impl PartialOrd for Score {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Score {
pub fn new_clamped(value: f32) -> Self {
let value = if value.is_nan() { 0.0 } else { value };
Score(value.clamp(-1.0, 1.0))
}
pub fn value(self) -> f32 {
self.0
}
}