use crate::transition::*;
use core::hash::Hash;
use routers_network::{Entry, Metadata, Network};
use rustc_hash::FxHashMap;
pub trait Solver<E, M, N>
where
E: Entry,
M: Metadata,
N: Network<E, M>,
{
fn solve<Emmis, Trans>(
&self,
transition: Transition<Emmis, Trans, E, M, N>,
runtime: &M::Runtime,
) -> Result<CollapsedPath<E>, MatchError>
where
Emmis: EmissionStrategy + Send + Sync,
Trans: TransitionStrategy<E, M, N> + Send + Sync;
#[inline]
fn path_builder<K, C>(source: &K, target: &K, parents: &FxHashMap<K, (K, C)>) -> Option<Vec<K>>
where
K: Eq + Hash + Copy,
{
let mut rev = vec![*source];
let mut next = source;
while let Some((parent, _)) = parents.get(next) {
if *next == *target {
rev.reverse();
return Some(rev);
}
rev.push(*parent);
next = parent;
}
None
}
}