use crate::ShapeLabelIdx;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ExtendAlternative {
bucket_shapes: Vec<ShapeLabelIdx>,
constraints: Vec<ShapeLabelIdx>,
}
impl ExtendAlternative {
pub fn with_bucket(idx: ShapeLabelIdx) -> Self {
ExtendAlternative {
bucket_shapes: vec![idx],
constraints: Vec::new(),
}
}
pub fn with_constraint(idx: ShapeLabelIdx) -> Self {
ExtendAlternative {
bucket_shapes: Vec::new(),
constraints: vec![idx],
}
}
pub fn with_constraints(idxs: Vec<ShapeLabelIdx>) -> Self {
ExtendAlternative {
bucket_shapes: Vec::new(),
constraints: idxs,
}
}
pub fn bucket_shapes(&self) -> &[ShapeLabelIdx] {
&self.bucket_shapes
}
pub fn constraints(&self) -> &[ShapeLabelIdx] {
&self.constraints
}
pub fn merge(&self, other: &Self) -> Self {
let mut result = self.clone();
for b in &other.bucket_shapes {
push_unique(&mut result.bucket_shapes, *b);
}
for c in &other.constraints {
push_unique(&mut result.constraints, *c);
}
result
}
}
fn push_unique(v: &mut Vec<ShapeLabelIdx>, x: ShapeLabelIdx) {
if !v.contains(&x) {
v.push(x);
}
}
pub(crate) fn cross_merge(left: Vec<ExtendAlternative>, right: Vec<ExtendAlternative>) -> Vec<ExtendAlternative> {
left.iter().flat_map(|a| right.iter().map(|b| a.merge(b))).collect()
}