use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ConfidenceState {
pub bloom: [u8; 32],
pub parity: u8,
pub certainty: f64,
}
impl ConfidenceState {
pub fn new(bloom: [u8; 32], parity: u8, certainty: f64) -> Self {
Self { bloom, parity, certainty }
}
pub fn default() -> Self {
Self {
bloom: [0u8; 32],
parity: 0,
certainty: 0.0,
}
}
pub fn check_alignment(&self) -> Vec<String> {
let mut violations = Vec::new();
if !(0.0..=1.0).contains(&self.certainty) {
violations.push("confidence.certainty must be 0-1".into());
}
violations
}
pub fn merge(&self, other: &Self) -> Self {
let mut bloom = [0u8; 32];
for i in 0..32 {
bloom[i] = self.bloom[i] | other.bloom[i];
}
Self {
bloom,
parity: self.parity | other.parity,
certainty: self.certainty.max(other.certainty),
}
}
}