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    #[must_use]
51    pub const fn enable_cross_ecosystem(&self) -> bool {
52        self.cross_ecosystem.enabled
53    }
54
55    /// Aggressive optimization for very large SBOMs (1000+)
56    #[must_use]
57    pub fn aggressive() -> Self {
58        Self {
59            lsh_threshold: 300,
60            cross_ecosystem: CrossEcosystemConfig::default(),
61            max_candidates: 50,
62            hungarian_threshold: 3000,
63            enable_swap_optimization: true,
64            max_swap_iterations: 50,
65        }
66    }
67
68    /// Conservative settings (for accuracy over speed)
69    #[must_use]
70    pub fn conservative() -> Self {
71        Self {
72            lsh_threshold: 1000,
73            cross_ecosystem: CrossEcosystemConfig::disabled(),
74            max_candidates: 150,
75            hungarian_threshold: 10000,
76            enable_swap_optimization: true,
77            max_swap_iterations: 200,
78        }
79    }
80}