use crate::{CfgLE, StateLE, StateLEExt};
use im::OrdSet as ArcOrdSet;
use pergola::{DefTraits, LatticeDef, LatticeElt};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::fmt::Debug;
use std::hash::Hash;
#[serde(bound = "")]
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, Hash, Default, Serialize, Deserialize)]
pub struct Opinion<ObjLD: LatticeDef, Peer: DefTraits> {
pub estimated_commit: StateLE<ObjLD, Peer>,
pub proposed_configs: ArcOrdSet<CfgLE<Peer>>,
pub candidate_object: LatticeElt<ObjLD>,
}
impl<ObjLD: LatticeDef, Peer: DefTraits> Opinion<ObjLD, Peer> {
pub fn same_estimated_commit_config(&self, other: &Self) -> bool {
self.estimated_commit.config() == other.estimated_commit.config()
}
pub fn same_estimated_and_proposed_configs(&self, other: &Self) -> bool {
self.same_estimated_commit_config(other) && self.proposed_configs == other.proposed_configs
}
}
impl<ObjLD: LatticeDef, Peer: DefTraits> std::cmp::Ord for Opinion<ObjLD, Peer>
where
ObjLD::T: Ord,
{
fn cmp(&self, other: &Self) -> Ordering {
let tup1 = (
&self.estimated_commit,
&self.proposed_configs,
&self.candidate_object,
);
let tup2 = (
&other.estimated_commit,
&other.proposed_configs,
&other.candidate_object,
);
tup1.cmp(&tup2)
}
}