dag: Add "dot" format output
This commit is contained in:
parent
8657cd8fc8
commit
bb3c1b5684
|
|
@ -5,6 +5,7 @@ use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::{BTreeMap, BTreeSet, VecDeque},
|
collections::{BTreeMap, BTreeSet, VecDeque},
|
||||||
fmt,
|
fmt,
|
||||||
|
fmt::Write,
|
||||||
ops::{ControlFlow, Deref, Index},
|
ops::{ControlFlow, Deref, Index},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -313,6 +314,23 @@ impl<K: Ord + Copy, V> Dag<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: Ord + Copy + fmt::Display, V> Dag<K, V> {
|
||||||
|
/// Return the graph in "dot" format.
|
||||||
|
pub fn to_dot(&self) -> String {
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
writeln!(output, "digraph G {{").ok();
|
||||||
|
for (k, v) in self.graph.iter() {
|
||||||
|
for d in &v.dependencies {
|
||||||
|
writeln!(output, "\t\"{k}\" -> \"{d}\";").ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln!(output, "}}").ok();
|
||||||
|
|
||||||
|
output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: Ord + Copy + fmt::Debug, V> Index<&K> for Dag<K, V> {
|
impl<K: Ord + Copy + fmt::Debug, V> Index<&K> for Dag<K, V> {
|
||||||
type Output = Node<K, V>;
|
type Output = Node<K, V>;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue