MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / compute_order

Function compute_order

atomic-core/src/output/alive/order.rs:454–489  ·  view source on GitHub ↗

Compute the output order using Tarjan's SCC algorithm. This function: 1. Runs Tarjan's algorithm to find all SCCs 2. Builds the conflict tree 3. Identifies forward edges # Arguments `graph` - The alive graph (will be modified to set SCC indices) # Returns An `OrderResult` containing SCCs and conflict information. # Example ```rust,ignore use atomic_core::output::alive::{AliveGraph, compute_

(graph: &mut AliveGraph)

Source from the content-addressed store, hash-verified

452/// println!("Found {} SCCs", order.num_sccs());
453/// ```
454pub fn compute_order(graph: &mut AliveGraph) -> OrderResult {
455 let mut result = OrderResult::new();
456
457 if graph.is_empty() {
458 return result;
459 }
460
461 let mut state = TarjanState::new(graph.len_vertices());
462
463 // Run Tarjan's algorithm starting from span 1 (root)
464 // Skip span 0 which is DUMMY
465 for i in 1..graph.len_vertices() {
466 let vid = VertexId::new(i);
467 if !graph.get_vertex(vid).is_visited() {
468 tarjan_visit(graph, vid, &mut state, &mut result);
469 }
470 }
471
472 // Count cyclic conflicts
473 result.cyclic_conflicts = result.sccs.iter().filter(|scc| scc.len() > 1).count();
474
475 // Build a simple conflict tree (can be enhanced later for nested conflicts)
476 build_conflict_tree(graph, &mut result);
477
478 // Structural invariant: the SCCs must partition the alive vertices. A
479 // violation here is the root of the silent duplication/omission class of
480 // bugs, so fail loudly (in debug/test builds) at the point of origin
481 // rather than letting corruption reach disk.
482 debug_assert!(
483 result.validate_partition(graph.len_vertices()).is_ok(),
484 "compute_order did not produce a vertex partition: {:?}",
485 result.validate_partition(graph.len_vertices())
486 );
487
488 result
489}
490
491/// Internal state for Tarjan's algorithm.
492struct TarjanState {

Calls 9

tarjan_visitFunction · 0.85
build_conflict_treeFunction · 0.85
len_verticesMethod · 0.80
is_visitedMethod · 0.80
get_vertexMethod · 0.80
is_emptyMethod · 0.45
countMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45