quorum_set/quorum/
coherent_impl.rs1use std::collections::BTreeSet;
2
3use crate::quorum::Coherent;
4use crate::quorum::coherent::FindCoherent;
5
6impl<NID> Coherent<NID, Vec<BTreeSet<NID>>> for Vec<BTreeSet<NID>>
9where NID: PartialOrd + Ord + Clone + 'static
10{
11 fn is_coherent_with(&self, other: &Vec<BTreeSet<NID>>) -> bool {
16 for a in self {
17 for b in other {
18 if a == b {
19 return true;
20 }
21 }
22 }
23 false
24 }
25}
26
27impl<NID> FindCoherent<NID, BTreeSet<NID>> for Vec<BTreeSet<NID>>
29where NID: PartialOrd + Ord + Clone + 'static
30{
31 fn find_coherent(&self, other: BTreeSet<NID>) -> Self {
32 if self.is_coherent_with(&vec![other.clone()]) {
33 vec![other]
34 } else if let Some(last) = self.last() {
35 vec![last.clone(), other]
36 } else {
37 vec![other]
38 }
39 }
40}