#![warn(missing_docs)]
#![doc = include_str!("../README.md")]
use std::cmp::Ordering::{self, *};
pub use ::{cc_traits, variadics};
use sealed::sealed;
pub mod algebra;
pub mod collections;
mod conflict;
mod dom_pair;
pub mod ght;
pub mod map_union;
pub mod map_union_with_tombstones;
mod ord;
mod pair;
mod point;
pub mod semiring_application;
pub mod set_union;
pub mod set_union_with_tombstones;
pub mod test;
pub mod tombstone;
pub mod union_find;
mod unit;
mod vec_union;
mod with_bot;
mod with_top;
pub use conflict::Conflict;
pub use dom_pair::DomPair;
pub use lattices_macro::*;
pub use ord::{Max, Min};
pub use pair::{Pair, PairBimorphism};
pub use point::Point;
pub use vec_union::VecUnion;
pub use with_bot::WithBot;
pub use with_top::WithTop;
#[sealed]
pub trait Lattice: Sized + Merge<Self> + LatticeOrd + NaiveLatticeOrd + IsBot + IsTop {}
#[sealed]
impl<T> Lattice for T where T: Sized + Merge<Self> + LatticeOrd + NaiveLatticeOrd + IsBot + IsTop {}
#[sealed]
pub trait Semiring<T>: Addition<T> + Multiplication<T> + Zero<T> + One<T> {}
pub trait Addition<Other> {
fn add(&mut self, other: Self);
fn add_owned(mut self, other: Self) -> Self
where
Self: Sized,
{
self.add(other);
self
}
}
pub trait Multiplication<Other> {
fn mul(&mut self, other: Self);
fn mul_owned(mut self, other: Self) -> Self
where
Self: Sized,
{
self.mul(other);
self
}
}
pub trait Zero<T> {
fn zero(&self) -> T;
}
pub trait One<T> {
fn one(&self) -> T;
}
pub trait Merge<Other> {
fn merge(&mut self, other: Other) -> bool;
fn merge_owned(mut this: Self, delta: Other) -> Self
where
Self: Sized,
{
Self::merge(&mut this, delta);
this
}
}
pub trait LatticeOrd<Rhs = Self>: PartialOrd<Rhs> {}
#[sealed]
pub trait NaiveLatticeOrd<Rhs = Self>
where
Self: Clone + Merge<Rhs> + Sized,
Rhs: Clone + Merge<Self>,
{
fn naive_cmp(&self, other: &Rhs) -> Option<Ordering> {
let mut self_a = self.clone();
let other_a = other.clone();
let self_b = self.clone();
let mut other_b = other.clone();
match (self_a.merge(other_a), other_b.merge(self_b)) {
(true, true) => None,
(true, false) => Some(Less),
(false, true) => Some(Greater),
(false, false) => Some(Equal),
}
}
}
#[sealed]
impl<This, Other> NaiveLatticeOrd<Other> for This
where
Self: Clone + Merge<Other>,
Other: Clone + Merge<Self>,
{
}
pub trait LatticeFrom<Other> {
fn lattice_from(other: Other) -> Self;
}
pub trait IsBot {
fn is_bot(&self) -> bool;
}
pub trait IsTop {
fn is_top(&self) -> bool;
}
pub trait Atomize: Merge<Self::Atom> {
type Atom: 'static + IsBot;
type AtomIter: 'static + Iterator<Item = Self::Atom>;
fn atomize(self) -> Self::AtomIter;
}
pub trait DeepReveal {
type Revealed;
fn deep_reveal(self) -> Self::Revealed;
}
pub trait LatticeMorphism<LatIn> {
type Output;
fn call(&mut self, lat_in: LatIn) -> Self::Output;
}
pub trait LatticeBimorphism<LatA, LatB> {
type Output;
fn call(&mut self, lat_a: LatA, lat_b: LatB) -> Self::Output;
}
pub fn closure_to_morphism<LatIn, LatOut, F>(
func: F,
) -> impl LatticeMorphism<LatIn, Output = LatOut>
where
F: FnMut(LatIn) -> LatOut,
{
struct FnMorphism<F>(F);
impl<F, LatIn, LatOut> LatticeMorphism<LatIn> for FnMorphism<F>
where
F: FnMut(LatIn) -> LatOut,
{
type Output = LatOut;
fn call(&mut self, lat_in: LatIn) -> Self::Output {
(self.0)(lat_in)
}
}
FnMorphism(func)
}
pub fn closure_to_bimorphism<LatA, LatB, LatOut, F>(
func: F,
) -> impl LatticeBimorphism<LatA, LatB, Output = LatOut>
where
F: FnMut(LatA, LatB) -> LatOut,
{
struct FnBimorphism<F>(F);
impl<F, LatA, LatB, LatOut> LatticeBimorphism<LatA, LatB> for FnBimorphism<F>
where
F: FnMut(LatA, LatB) -> LatOut,
{
type Output = LatOut;
fn call(&mut self, lat_a: LatA, lat_b: LatB) -> Self::Output {
(self.0)(lat_a, lat_b)
}
}
FnBimorphism(func)
}