use std::rc::Rc; use crate::func::*; use super::comparator::Comparator; pub type NodeRc<'a, BT> = Rc<>::Node>; pub type ReferenceRc<'a, BT> = Rc<>::Reference>; pub type TreeRc<'a, BT> = Rc<>::Tree>; pub type KeyRc<'a, BT> = Rc<>::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, >::T>; pub trait BinaryTrees<'a>: 'a { type Node: 'a; type Reference: 'a; type Tree: 'a; type Key: 'a; type Comparator: Comparator; 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>; } 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>>; }