zeitgeist_protocol/
confidence.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8pub struct ConfidenceState {
9 pub bloom: [u8; 32],
11 pub parity: u8,
13 pub certainty: f64,
15}
16
17impl ConfidenceState {
18 pub fn new(bloom: [u8; 32], parity: u8, certainty: f64) -> Self {
19 Self { bloom, parity, certainty }
20 }
21
22 pub fn default() -> Self {
23 Self {
24 bloom: [0u8; 32],
25 parity: 0,
26 certainty: 0.0,
27 }
28 }
29
30 pub fn check_alignment(&self) -> Vec<String> {
32 let mut violations = Vec::new();
33 if !(0.0..=1.0).contains(&self.certainty) {
34 violations.push("confidence.certainty must be 0-1".into());
35 }
36 violations
37 }
38
39 pub fn merge(&self, other: &Self) -> Self {
42 let mut bloom = [0u8; 32];
43 for i in 0..32 {
44 bloom[i] = self.bloom[i] | other.bloom[i];
45 }
46 Self {
47 bloom,
48 parity: self.parity | other.parity,
49 certainty: self.certainty.max(other.certainty),
50 }
51 }
52}