Skip to main content

sbom_tools/diff/
engine_config.rs

1//! Configuration types for the diff engine.
2
3use crate::matching::CrossEcosystemConfig;
4
5/// Method used for component assignment.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7#[allow(dead_code)]
8pub enum AssignmentMethod {
9    /// Optimal assignment using Hungarian algorithm (Kuhn-Munkres)
10    #[default]
11    Hungarian,
12    /// Greedy assignment with 2-opt swap optimization
13    GreedyWithSwaps,
14    /// Simple greedy assignment (fastest, may be suboptimal)
15    Greedy,
16}
17
18/// Configuration for large SBOM optimization.
19#[derive(Debug, Clone)]
20pub struct LargeSbomConfig {
21    /// Minimum component count to enable LSH-based matching
22    pub lsh_threshold: usize,
23    /// Cross-ecosystem matching configuration
24    pub cross_ecosystem: CrossEcosystemConfig,
25    /// Maximum candidates per component
26    pub max_candidates: usize,
27    /// Maximum problem size for Hungarian algorithm (falls back to greedy+swaps above this)
28    pub hungarian_threshold: usize,
29    /// Enable 2-opt swap optimization for greedy assignment
30    pub enable_swap_optimization: bool,
31    /// Maximum swap iterations for 2-opt optimization
32    pub max_swap_iterations: usize,
33}
34
35impl Default for LargeSbomConfig {
36    fn default() -> Self {
37        Self {
38            lsh_threshold: 500,
39            cross_ecosystem: CrossEcosystemConfig::default(),
40            max_candidates: 100,
41            hungarian_threshold: 5000,
42            enable_swap_optimization: true,
43            max_swap_iterations: 100,
44        }
45    }
46}
47
48impl LargeSbomConfig {
49    /// Check if cross-ecosystem matching is enabled.
50    pub fn enable_cross_ecosystem(&self) -> bool {
51        self.cross_ecosystem.enabled
52    }
53
54    /// Aggressive optimization for very large SBOMs (1000+)
55    pub fn aggressive() -> Self {
56        Self {
57            lsh_threshold: 300,
58            cross_ecosystem: CrossEcosystemConfig::default(),
59            max_candidates: 50,
60            hungarian_threshold: 3000,
61            enable_swap_optimization: true,
62            max_swap_iterations: 50,
63        }
64    }
65
66    /// Conservative settings (for accuracy over speed)
67    pub fn conservative() -> Self {
68        Self {
69            lsh_threshold: 1000,
70            cross_ecosystem: CrossEcosystemConfig::disabled(),
71            max_candidates: 150,
72            hungarian_threshold: 10000,
73            enable_swap_optimization: true,
74            max_swap_iterations: 200,
75        }
76    }
77}