Module generic

Module generic 

Source
Expand description

Generic topological sorting for any data structure.

This module provides topological sorting that works with any graph-like structure via higher-order functions, similar to the generic cycle detection.

§Submodules

  • impact - Impact analysis (descendants, ancestors, blast radius)
  • metrics - Graph metrics and statistics

§Examples

use ascii_dag::layout::generic::topological_sort_fn;

// Example: Sort tasks by dependencies
let get_deps = |task: &&str| match *task {
    "deploy" => vec!["test", "build"],
    "test" => vec!["build"],
    "build" => vec!["compile"],
    "compile" => vec![],
    _ => vec![],
};

let tasks = ["deploy", "test", "build", "compile"];
if let Ok(sorted) = topological_sort_fn(&tasks, get_deps) {
    // sorted = ["compile", "build", "test", "deploy"]
    assert_eq!(sorted[0], "compile");  // No dependencies, comes first
    assert_eq!(sorted[3], "deploy");   // Depends on everything, comes last
}

Modules§

impact
Impact analysis for dependency graphs.
metrics
Graph metrics and statistics.

Traits§

TopologicallySortable
Trait for types that support topological sorting.

Functions§

topological_sort_fn
Performs topological sorting on a collection of items using a dependency function.