use std::collections::BTreeSet;
use crate::quorum::QuorumBridge;
use crate::quorum::QuorumIntersection;
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(&other);
if intersects == Some(true) {
vec![other]
} else if let Some(last) = self.last() {
vec![last.clone(), other]
} else {
vec![other]
}
}
fn joint_with(&self, other: BTreeSet<ID>) -> Self {
if self.is_empty() {
return vec![];
}
let mut joint = self.clone();
joint.push(other);
joint
}
}
impl<ID> QuorumBridge<Vec<BTreeSet<ID>>> for Vec<BTreeSet<ID>>
where ID: Ord + Clone
{
fn bridge_to(&self, other: Vec<BTreeSet<ID>>) -> Self {
let intersects = self.intersects_with(&other);
if intersects == Some(true) {
other
} else if let Some(last) = self.last() {
let mut joint = vec![last.clone()];
joint.extend(other);
joint
} else {
other
}
}
fn joint_with(&self, other: Vec<BTreeSet<ID>>) -> Self {
if self.is_empty() || other.is_empty() {
return vec![];
}
let mut joint = self.clone();
joint.extend(other);
joint
}
}