use std::collections::BTreeSet;
use crate::quorum::Coherent;
use crate::quorum::coherent::FindCoherent;
impl<NID> Coherent<NID, Vec<BTreeSet<NID>>> for Vec<BTreeSet<NID>>
where NID: PartialOrd + Ord + Clone + 'static
{
fn is_coherent_with(&self, other: &Vec<BTreeSet<NID>>) -> bool {
for a in self {
for b in other {
if a == b {
return true;
}
}
}
false
}
}
impl<NID> FindCoherent<NID, BTreeSet<NID>> for Vec<BTreeSet<NID>>
where NID: PartialOrd + Ord + Clone + 'static
{
fn find_coherent(&self, other: BTreeSet<NID>) -> Self {
if self.is_coherent_with(&vec![other.clone()]) {
vec![other]
} else if let Some(last) = self.last() {
vec![last.clone(), other]
} else {
vec![other]
}
}
}