mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-16 00:00:37 +08:00
dag: Add "dot" format output
This commit is contained in:
@@ -5,6 +5,7 @@ use std::{
|
||||
cmp::Ordering,
|
||||
collections::{BTreeMap, BTreeSet, VecDeque},
|
||||
fmt,
|
||||
fmt::Write,
|
||||
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> {
|
||||
type Output = Node<K, V>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user