1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use std::fmt::{Display, Formatter, Result};
use crate::{egraph::EGraph, expr::Language};
pub struct Dot<'a, L: Language, M> {
egraph: &'a EGraph<L, M>,
}
impl<'a, L: Language, M> Dot<'a, L, M> {
pub fn new(egraph: &EGraph<L, M>) -> Dot<L, M> {
Dot { egraph }
}
}
impl<'a, L: Language, M> Display for Dot<'a, L, M> {
fn fmt(&self, f: &mut Formatter) -> Result {
writeln!(f, "digraph {{")?;
writeln!(f, " compound=true")?;
for class in self.egraph.classes() {
writeln!(f, " subgraph cluster_{} {{", class.id)?;
writeln!(f, " style=dotted")?;
for (i, node) in class.iter().enumerate() {
writeln!(f, " {}.{}[label = \"{}\"]", class.id, i, node.symbol())?;
}
writeln!(f, " }}")?;
}
for class in self.egraph.classes() {
for (i_in_class, node) in class.iter().enumerate() {
for (arg_i, child) in node.children().iter().enumerate() {
let child_leader = self.egraph.just_find(*child);
writeln!(
f,
" {}.{} -> {}.0 [lhead = cluster_{}, label = {}]",
class.id, i_in_class, child, child_leader, arg_i
)?;
}
}
}
write!(f, "}}")
}
}