48 lines
1.5 KiB
Rust
48 lines
1.5 KiB
Rust
use std::rc::Rc;
|
|
|
|
use crate::func::*;
|
|
|
|
use super::comparator::Comparator;
|
|
|
|
pub type NodeRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Node>;
|
|
pub type ReferenceRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Reference>;
|
|
pub type TreeRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Tree>;
|
|
pub type KeyRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Key>;
|
|
|
|
pub type Split<'a, BT> = (TreeRc<'a, BT>, TreeRc<'a, BT>, KeyRc<'a, BT>);
|
|
pub type KeySplit<'a, BT> = (TreeRc<'a, BT>, TreeRc<'a, BT>);
|
|
|
|
pub type Wrapped<'a, BT, A> = Wrap<'a, A, <BT as BinaryTrees<'a>>::T>;
|
|
|
|
pub trait BinaryTrees<'a>: 'a {
|
|
type Node: 'a;
|
|
type Reference: 'a;
|
|
type Tree: 'a;
|
|
type Key: 'a;
|
|
type Comparator: Comparator<Self::Key>;
|
|
|
|
type T: Monad<'a>;
|
|
|
|
fn comparator(&self) -> &Self::Comparator;
|
|
fn split(&self, node: Self::Node) -> Split<'a, Self>;
|
|
fn to_tree(&self, node: Self::Node) -> TreeRc<'a, Self>;
|
|
fn resolve(&self, reference: Self::Reference) -> Wrapped<'a, Self, NodeRc<'a, Self>>;
|
|
fn equal(&self, rhs: Self::Reference, lhs: Self::Reference) -> bool;
|
|
fn refer(&self, tree: Self::Tree) -> Option<ReferenceRc<'a, Self>>;
|
|
}
|
|
|
|
pub trait BinaryTreesMutable<'a>: BinaryTrees<'a> {
|
|
fn join_key(
|
|
&self,
|
|
tl: Self::Tree,
|
|
key: KeyRc<'a, Self>,
|
|
tr: Self::Tree,
|
|
) -> Wrapped<'a, Self, NodeRc<'a, Self>>;
|
|
fn join(&self, tl: Self::Tree, tr: Self::Tree) -> Wrapped<'a, Self, TreeRc<'a, Self>>;
|
|
fn split_key(
|
|
&self,
|
|
tree: Self::Tree,
|
|
key: KeyRc<'a, Self>,
|
|
) -> Wrapped<'a, Self, KeySplit<'a, Self>>;
|
|
}
|