graphfind_rs/petgraph/
pattern_graphs.rs1use crate::pattern_matching::{PatternElement, PatternGraph};
2
3impl<NodeWeight, EdgeWeight> PatternGraph<NodeWeight, EdgeWeight>
6 for petgraph::graph::Graph<PatternElement<NodeWeight>, PatternElement<EdgeWeight>>
7{
8 fn add_hidden_node<C>(&mut self, condition: C) -> Self::NodeRef
10 where
11 C: Fn(&NodeWeight) -> bool + 'static,
12 {
13 self.add_node(PatternElement::new(Box::new(condition), true))
14 }
15
16 fn add_node<C>(&mut self, condition: C) -> Self::NodeRef
18 where
19 C: Fn(&NodeWeight) -> bool + 'static,
20 {
21 self.add_node(PatternElement::new(Box::new(condition), false))
22 }
23
24 fn add_hidden_edge<C>(
26 &mut self,
27 from: Self::NodeRef,
28 to: Self::NodeRef,
29 condition: C,
30 ) -> Self::EdgeRef
31 where
32 C: Fn(&EdgeWeight) -> bool + 'static,
33 {
34 self.add_edge(from, to, PatternElement::new(Box::new(condition), true))
35 }
36
37 fn add_edge<C>(&mut self, from: Self::NodeRef, to: Self::NodeRef, condition: C) -> Self::EdgeRef
39 where
40 C: Fn(&EdgeWeight) -> bool + 'static,
41 {
42 if !self.node_weight(from).unwrap().should_appear()
43 || !self.node_weight(to).unwrap().should_appear()
44 {
45 panic!("Must not refer to an edge that refers to nodes that cannot be referred!")
46 }
47 self.add_edge(from, to, PatternElement::new(Box::new(condition), false))
48 }
49}