use crate::control::WorkMeter;
use crate::perfect::ProjectiveComplex;
use crate::tilting_complex::{CertifiedSiltingComplex, Interrupt, summands_isomorphic};
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TiltingComplexKey(String);
impl TiltingComplexKey {
pub fn new(complex: &CertifiedSiltingComplex) -> TiltingComplexKey {
let mut shapes: Vec<String> = complex
.candidate()
.summands()
.iter()
.map(summand_shape)
.collect();
shapes.sort();
TiltingComplexKey(shapes.join("|"))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
fn summand_shape(summand: &ProjectiveComplex) -> String {
let complex = summand.complex();
let vertices = complex.terms()[0].algebra().quiver().num_vertices() as usize;
let terms: Vec<Vec<usize>> = summand
.terms()
.iter()
.map(|term| {
let mut counts = vec![0; vertices];
term.vertices()
.iter()
.for_each(|&vertex| counts[vertex as usize] += 1);
counts
})
.collect();
format!("{}:{terms:?}", complex.lower())
}
pub(super) fn isomorphic(
left: &CertifiedSiltingComplex,
right: &CertifiedSiltingComplex,
meter: &mut WorkMeter,
) -> Result<bool, Interrupt> {
let shapes: Vec<String> = right
.candidate()
.summands()
.iter()
.map(summand_shape)
.collect();
if left.candidate().len() != shapes.len() {
return Ok(false);
}
for (index, summand) in left.candidate().summands().iter().enumerate() {
let shape = summand_shape(summand);
let mut matched = false;
for other in (0..shapes.len()).filter(|&other| shapes[other] == shape) {
if summands_isomorphic(left, index, right, other, meter)? {
matched = true;
break;
}
}
if !matched {
return Ok(false);
}
}
Ok(true)
}