1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ---------------- [ File: capability-grower-configuration-comparison/src/compare_outcome.rs ]
crate::ix!();
#[derive(Debug, Clone, PartialEq)]
pub enum CompareOutcome {
/// Perfect or near-perfect match (score=1.0).
Exact,
/// Partial or probabilistic match, with a numeric [0..1] score.
Partial(f32),
/// A definite mismatch or violation of a hard constraint.
Incompatible,
}
impl CompareOutcome {
/// Multiplicative combination approach for partial checks
pub fn combine(&self, other: &CompareOutcome) -> CompareOutcome {
use CompareOutcome::*;
match (self, other) {
(Incompatible, _) | (_, Incompatible) => Incompatible,
(Exact, Exact) => Exact,
(Exact, Partial(x)) => Partial(*x),
(Partial(x), Exact) => Partial(*x),
(Partial(a), Partial(b)) => {
let combined = a * b;
Partial(combined)
}
}
}
/// Converts an outcome to a numeric [0..1].
pub fn to_score(&self) -> f32 {
match self {
CompareOutcome::Incompatible => 0.0,
CompareOutcome::Exact => 1.0,
CompareOutcome::Partial(x) => *x,
}
}
/// A convenience for checking equality with `CompareOutcome::Exact`
pub fn is_exact(&self) -> bool {
matches!(self, CompareOutcome::Exact)
}
/// A convenience for checking if self is `Incompatible`.
pub fn is_incompatible(&self) -> bool {
matches!(self, CompareOutcome::Incompatible)
}
}