use crate::graph::Graph;
use super::Matcher;
pub struct PatternElement<Weight> {
condition: Box<Matcher<Weight>>,
ignore: bool,
}
impl<Weight> PatternElement<Weight> {
pub fn new(condition: Box<Matcher<Weight>>, ignore: bool) -> Self {
Self { condition, ignore }
}
pub fn should_appear(&self) -> bool {
!self.ignore
}
pub fn may_match(&self, element: &Weight) -> bool {
(self.condition)(element)
}
}
pub trait PatternGraph<NodeWeight, EdgeWeight>:
Graph<PatternElement<NodeWeight>, PatternElement<EdgeWeight>>
{
fn add_node<C>(&mut self, condition: C) -> Self::NodeRef
where
C: Fn(&NodeWeight) -> bool + 'static;
fn add_hidden_node<C>(&mut self, condition: C) -> Self::NodeRef
where
C: Fn(&NodeWeight) -> bool + 'static;
fn add_edge<C>(
&mut self,
from: Self::NodeRef,
to: Self::NodeRef,
condition: C,
) -> Self::EdgeRef
where
C: Fn(&EdgeWeight) -> bool + 'static;
fn add_hidden_edge<C>(
&mut self,
from: Self::NodeRef,
to: Self::NodeRef,
condition: C,
) -> Self::EdgeRef
where
C: Fn(&EdgeWeight) -> bool + 'static;
}