Helper to build a graph from a list of edges. Each edge is (from, to) meaning "from" depends on "to". We take the root separately to build a graph without edges.
(
edges: &[(SubjectVersion, Option<SubjectVersion>)],
)
| 940 | /// |
| 941 | /// We take the root separately to build a graph without edges. |
| 942 | fn build_graph( |
| 943 | edges: &[(SubjectVersion, Option<SubjectVersion>)], |
| 944 | ) -> HashMap<SubjectVersion, Vec<SubjectVersion>> { |
| 945 | let mut graph: HashMap<SubjectVersion, Vec<SubjectVersion>> = HashMap::new(); |
| 946 | |
| 947 | // Add edges: from depends on to |
| 948 | for (from, to) in edges { |
| 949 | let deps = graph.entry(from.clone()).or_default(); |
| 950 | if let Some(to) = to { |
| 951 | deps.push(to.clone()); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | graph |
| 956 | } |
| 957 | |
| 958 | /// Verify that all edges are respected in the ordering. |
| 959 | /// For edge (from, to) where 'from' depends on 'to': |