use super::object::Hypergraph;
use crate::array::{Array, ArrayKind};
use crate::finite_function::FiniteFunction;
use core::fmt::Debug;
#[derive(Debug)]
pub enum InvalidHypergraphArrow {
NotNaturalW,
NotNaturalX,
}
pub struct HypergraphArrow<K: ArrayKind, O, A> {
pub source: Hypergraph<K, O, A>,
pub target: Hypergraph<K, O, A>,
pub w: FiniteFunction<K>,
pub x: FiniteFunction<K>,
}
impl<K: ArrayKind, O, A> HypergraphArrow<K, O, A>
where
K::Type<O>: Array<K, O>,
K::Type<A>: Array<K, A>,
{
pub fn new(
source: Hypergraph<K, O, A>,
target: Hypergraph<K, O, A>,
w: FiniteFunction<K>,
x: FiniteFunction<K>,
) -> Result<Self, InvalidHypergraphArrow> {
HypergraphArrow {
source,
target,
w,
x,
}
.validate()
}
pub fn validate(self) -> Result<Self, InvalidHypergraphArrow> {
let g = &self.source;
let h = &self.target;
if g.w != (&self.w >> &h.w).unwrap() {
return Err(InvalidHypergraphArrow::NotNaturalW);
}
if g.x != (&self.x >> &h.x).unwrap() {
return Err(InvalidHypergraphArrow::NotNaturalX);
}
Ok(self)
}
}
impl<K: ArrayKind, O: Debug, A: Debug> Debug for HypergraphArrow<K, O, A>
where
K::Index: Debug,
K::Type<K::I>: Debug,
K::Type<A>: Debug,
K::Type<O>: Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HypergraphArrow")
.field("source", &self.source)
.field("target", &self.target)
.field("w", &self.w)
.field("x", &self.x)
.finish()
}
}
impl<K: ArrayKind, O: Debug, A: Debug> Clone for HypergraphArrow<K, O, A>
where
K::Type<K::I>: Clone,
K::Type<A>: Clone,
K::Type<O>: Clone,
{
fn clone(&self) -> Self {
Self {
source: self.source.clone(),
target: self.target.clone(),
w: self.w.clone(),
x: self.x.clone(),
}
}
}