use std::collections::BTreeSet;
use crate::quorum::QuorumBridge;
use crate::quorum::QuorumIntersection;
impl<ID> QuorumIntersection<Vec<BTreeSet<ID>>> for Vec<BTreeSet<ID>>
where ID: Ord + Clone
{
fn intersects_with(&self, other: &Vec<BTreeSet<ID>>) -> Option<bool> {
let either_is_empty = self.is_empty() || other.is_empty();
if either_is_empty {
return Some(false);
}
for a in self {
for b in other {
if a == b {
return Some(true);
}
}
}
None
}
}
impl<ID> QuorumBridge<BTreeSet<ID>> for Vec<BTreeSet<ID>>
where ID: Ord + Clone
{
fn bridge_to(&self, other: BTreeSet<ID>) -> Self {
let intersects = self.intersects_with(&vec![other.clone()]);
if intersects == Some(true) {
vec![other]
} else if let Some(last) = self.last() {
vec![last.clone(), other]
} else {
vec![other]
}
}
}