use crate::PosetError;
use std::cmp::Ordering;
pub trait PartialOrderBehaviour {
type Element;
fn pc(&self, a: &Self::Element, b: &Self::Element) -> Option<Ordering> {
match (self.ge(a, b), self.ge(b, a)) {
(true, true) => Some(Ordering::Equal),
(true, _) => Some(Ordering::Greater),
(_, true) => Some(Ordering::Less),
_ => None,
}
}
fn le(&self, a: &Self::Element, b: &Self::Element) -> bool {
self.ge(b, a)
}
fn ge(&self, a: &Self::Element, b: &Self::Element) -> bool;
fn gt(&self, a: &Self::Element, b: &Self::Element) -> bool {
self.ge(a, b) && !self.ge(b, a)
}
fn lt(&self, a: &Self::Element, b: &Self::Element) -> bool {
self.ge(b, a) && !self.ge(a, b)
}
fn eq(&self, a: &Self::Element, b: &Self::Element) -> bool {
self.ge(a, b) && self.ge(b, a)
}
fn ip(&self, a: &Self::Element, b: &Self::Element) -> bool {
!self.ge(a, b) && !self.ge(b, a)
}
fn cp(&self, a: &Self::Element, b: &Self::Element) -> bool {
self.ge(a, b) || self.ge(b, a)
}
}
pub trait PosetBehaviour: PartialOrderBehaviour {
type POrder: PartialOrderBehaviour<Element = Self::Element>;
fn add(&mut self, element: impl Into<Self::Element>);
fn elements(&self) -> impl Iterator<Item = &Self::Element>;
fn replace_elements(&mut self, elements: impl IntoIterator<Item = impl Into<Self::Element>>);
fn replace_partial_order(&mut self, p_ord: impl Into<Self::POrder>);
fn cardinality(&self) -> usize;
fn partial_order(&self) -> &Self::POrder;
fn maxima(&self) -> Result<impl IntoIterator<Item = &Self::Element>, PosetError>;
fn minima(&self) -> Result<impl IntoIterator<Item = &Self::Element>, PosetError>;
fn cover(&self, x: &Self::Element, y: &Self::Element) -> bool;
fn cover_in_pool<'a>(
&self,
x: &Self::Element,
y: &Self::Element,
pool: impl IntoIterator<Item = &'a Self::Element>,
) -> bool
where
Self::Element: 'a;
}