Skip to main content

_diffctx/config/
edge_weights.rs

1use once_cell::sync::Lazy;
2
3pub struct DockerWeights {
4    pub weight: f64,
5    pub copy_weight: f64,
6    pub compose_weight: f64,
7    pub reverse_factor: f64,
8    pub compose_context_modifier: f64,
9    pub compose_volume_modifier: f64,
10}
11
12impl Default for DockerWeights {
13    fn default() -> Self {
14        Self {
15            weight: 0.55,
16            copy_weight: 0.65,
17            compose_weight: 0.50,
18            reverse_factor: 0.40,
19            compose_context_modifier: 0.7,
20            compose_volume_modifier: 0.6,
21        }
22    }
23}
24
25pub struct KubernetesWeights {
26    pub weight: f64,
27    pub configmap_secret_weight: f64,
28    pub service_weight: f64,
29    pub selector_weight: f64,
30    pub image_weight: f64,
31    pub reverse_factor: f64,
32}
33
34impl Default for KubernetesWeights {
35    fn default() -> Self {
36        Self {
37            weight: 0.65,
38            configmap_secret_weight: 0.70,
39            service_weight: 0.60,
40            selector_weight: 0.55,
41            image_weight: 0.40,
42            reverse_factor: 0.45,
43        }
44    }
45}
46
47pub struct HelmWeights {
48    pub weight: f64,
49    pub reverse_factor: f64,
50    pub value_modifier: f64,
51    pub definition_modifier: f64,
52    pub configmap_modifier: f64,
53}
54
55impl Default for HelmWeights {
56    fn default() -> Self {
57        Self {
58            weight: 0.70,
59            reverse_factor: 0.45,
60            value_modifier: 0.8,
61            definition_modifier: 0.9,
62            configmap_modifier: 0.5,
63        }
64    }
65}
66
67pub struct BuildSystemWeights {
68    pub file_ref_weight: f64,
69    pub reverse_factor: f64,
70}
71
72impl Default for BuildSystemWeights {
73    fn default() -> Self {
74        Self {
75            file_ref_weight: 0.60,
76            reverse_factor: 0.35,
77        }
78    }
79}
80
81pub struct CicdWeights {
82    pub weight: f64,
83    pub script_weight: f64,
84    pub reverse_factor: f64,
85    pub script_modifier: f64,
86}
87
88impl Default for CicdWeights {
89    fn default() -> Self {
90        Self {
91            weight: 0.55,
92            script_weight: 0.60,
93            reverse_factor: 0.35,
94            script_modifier: 0.8,
95        }
96    }
97}
98
99pub struct PythonSemanticWeights {
100    pub import_weight: f64,
101    pub import_confirmed_boost: f64,
102    pub import_unconfirmed_penalty: f64,
103    pub reverse_factor: f64,
104}
105
106impl Default for PythonSemanticWeights {
107    fn default() -> Self {
108        Self {
109            import_weight: 0.75,
110            import_confirmed_boost: 1.5,
111            import_unconfirmed_penalty: 0.2,
112            reverse_factor: 0.5,
113        }
114    }
115}
116
117pub struct JavascriptSemanticWeights {
118    pub import_weight: f64,
119    pub reverse_factor: f64,
120}
121
122impl Default for JavascriptSemanticWeights {
123    fn default() -> Self {
124        Self {
125            import_weight: 0.55,
126            reverse_factor: 0.5,
127        }
128    }
129}
130
131pub struct GoSemanticWeights {
132    pub init_same_package_weight: f64,
133}
134
135impl Default for GoSemanticWeights {
136    fn default() -> Self {
137        Self {
138            init_same_package_weight: 0.15,
139        }
140    }
141}
142
143pub struct OpenapiSemanticWeights {
144    pub marker_scan_lines: usize,
145}
146
147impl Default for OpenapiSemanticWeights {
148    fn default() -> Self {
149        Self {
150            marker_scan_lines: 5,
151        }
152    }
153}
154
155pub struct AnsibleSemanticWeights {
156    pub sibling_modifier: f64,
157}
158
159impl Default for AnsibleSemanticWeights {
160    fn default() -> Self {
161        Self {
162            sibling_modifier: 0.6,
163        }
164    }
165}
166
167pub struct CFamilySemanticWeights {
168    pub base_weight: f64,
169}
170
171impl Default for CFamilySemanticWeights {
172    fn default() -> Self {
173        Self { base_weight: 0.70 }
174    }
175}
176
177pub struct TerraformSemanticWeights {
178    pub weight: f64,
179    pub reverse_factor: f64,
180    pub module_source_modifier: f64,
181}
182
183impl Default for TerraformSemanticWeights {
184    fn default() -> Self {
185        Self {
186            weight: 0.60,
187            reverse_factor: 0.40,
188            module_source_modifier: 0.8,
189        }
190    }
191}
192
193pub struct TagsSemanticWeights {
194    pub weight: f64,
195    pub reverse_factor: f64,
196    pub max_fragments_per_ident: usize,
197    pub min_ident_len: usize,
198}
199
200impl Default for TagsSemanticWeights {
201    fn default() -> Self {
202        Self {
203            weight: 0.30,
204            reverse_factor: 0.70,
205            max_fragments_per_ident: 5,
206            min_ident_len: 3,
207        }
208    }
209}
210
211pub struct SemanticDiscoveryConfig {
212    pub max_depth: usize,
213    pub min_identifier_length: usize,
214    pub min_ref_length_for_path_match: usize,
215}
216
217impl Default for SemanticDiscoveryConfig {
218    fn default() -> Self {
219        Self {
220            max_depth: 2,
221            min_identifier_length: 2,
222            min_ref_length_for_path_match: 3,
223        }
224    }
225}
226
227pub static DOCKER: Lazy<DockerWeights> = Lazy::new(DockerWeights::default);
228pub static KUBERNETES: Lazy<KubernetesWeights> = Lazy::new(KubernetesWeights::default);
229pub static HELM: Lazy<HelmWeights> = Lazy::new(HelmWeights::default);
230pub static BUILD_SYSTEM: Lazy<BuildSystemWeights> = Lazy::new(BuildSystemWeights::default);
231pub static CICD: Lazy<CicdWeights> = Lazy::new(CicdWeights::default);
232pub static PYTHON_SEMANTIC: Lazy<PythonSemanticWeights> = Lazy::new(PythonSemanticWeights::default);
233pub static JAVASCRIPT_SEMANTIC: Lazy<JavascriptSemanticWeights> =
234    Lazy::new(JavascriptSemanticWeights::default);
235pub static TERRAFORM_SEMANTIC: Lazy<TerraformSemanticWeights> =
236    Lazy::new(TerraformSemanticWeights::default);
237pub static GO_SEMANTIC: Lazy<GoSemanticWeights> = Lazy::new(GoSemanticWeights::default);
238pub static ANSIBLE_SEMANTIC: Lazy<AnsibleSemanticWeights> =
239    Lazy::new(AnsibleSemanticWeights::default);
240pub static OPENAPI_SEMANTIC: Lazy<OpenapiSemanticWeights> =
241    Lazy::new(OpenapiSemanticWeights::default);
242pub static C_FAMILY_SEMANTIC: Lazy<CFamilySemanticWeights> =
243    Lazy::new(CFamilySemanticWeights::default);
244pub static TAGS_SEMANTIC: Lazy<TagsSemanticWeights> = Lazy::new(TagsSemanticWeights::default);
245pub static SEMANTIC_DISCOVERY: Lazy<SemanticDiscoveryConfig> =
246    Lazy::new(SemanticDiscoveryConfig::default);