pub struct BuildGraph { /* private fields */ }Expand description
A validated, acyclic build graph.
Construct one with GraphBuilder. Once built, a graph is immutable and known to be acyclic,
so traversals need no cycle guard.
use critpath_core::{EdgeKind, GraphBuilder, Millis, Unit, UnitKind};
let mut builder = GraphBuilder::new();
let lib = builder.add_unit(Unit {
package: "leaf".to_owned(),
version: "1.0.0".to_owned(),
target: "leaf".to_owned(),
kind: UnitKind::Lib,
total: Millis::new(800),
metadata_at: Some(Millis::new(600)),
requires_full_closure: false,
})?;
let bin = builder.add_unit(Unit {
package: "app".to_owned(),
version: "1.0.0".to_owned(),
target: "app".to_owned(),
kind: UnitKind::Bin,
total: Millis::new(200),
metadata_at: None,
requires_full_closure: true,
})?;
builder.add_edge(lib, bin, EdgeKind::Full)?;
let graph = builder.build()?;
assert_eq!(graph.len(), 2);
assert_eq!(graph.total_work(), Millis::new(1_000));Implementations§
Source§impl BuildGraph
impl BuildGraph
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
How many edges the graph holds, after duplicates have been merged.
Examples found in repository?
78fn main() -> Result<(), Box<dyn Error>> {
79 let executors = NonZeroU32::new(16).ok_or("16 is not zero")?;
80 println!(
81 "{:>7} {:>8} {:>10} {:>10} {:>10}",
82 "units", "edges", "construct", "analyse", "simulate"
83 );
84 for &(units, fan_in) in &[(1_000, 4), (5_000, 4), (20_000, 6), (50_000, 6)] {
85 let start = Instant::now();
86 let graph = build(units, fan_in)?;
87 let constructed = start.elapsed();
88
89 let start = Instant::now();
90 let analysis = analyze(&graph);
91 let analysed = start.elapsed();
92
93 let start = Instant::now();
94 let schedule = simulate(&graph, executors, Policy::CargoLike);
95 let simulated = start.elapsed();
96
97 println!(
98 "{:>7} {:>8} {:>10.1?} {:>10.1?} {:>10.1?} critical path {}, makespan {}",
99 units,
100 graph.edge_count(),
101 constructed,
102 analysed,
103 simulated,
104 analysis.critical_path_len(),
105 schedule.makespan(),
106 );
107 }
108 Ok(())
109}Sourcepub fn total_work(&self) -> Millis
pub fn total_work(&self) -> Millis
The sum of every unit’s duration, which is the total work a build must perform.
Sourcepub fn unit(&self, id: UnitId) -> Option<&Unit>
pub fn unit(&self, id: UnitId) -> Option<&Unit>
The unit id refers to, or None if the index is outside this graph.
An identifier belonging to a different graph is not detected: identifiers are dense
indices, so a foreign one reads as None only when it points past the end, and otherwise
names a different unit. Do not mix identifiers between graphs.
Sourcepub fn units(&self) -> impl ExactSizeIterator<Item = (UnitId, &Unit)> + '_
pub fn units(&self) -> impl ExactSizeIterator<Item = (UnitId, &Unit)> + '_
Every unit, in identifier order.
Sourcepub fn dependencies(&self, id: UnitId) -> Option<&[Dep]>
pub fn dependencies(&self, id: UnitId) -> Option<&[Dep]>
The units id depends on, or None if the index is outside this graph.
Sourcepub fn dependents(&self, id: UnitId) -> Option<&[Dep]>
pub fn dependents(&self, id: UnitId) -> Option<&[Dep]>
The units that depend on id, or None if the index is outside this graph.
Sourcepub fn topological_order(&self) -> &[UnitId]
pub fn topological_order(&self) -> &[UnitId]
Every unit in an order that places each dependency before its dependents.