binary rework

This commit is contained in:
AF 2023-05-28 21:11:55 +00:00
parent 7296d97ecb
commit 4736d8d112

View File

@ -2,6 +2,8 @@ use std::rc::Rc;
use crate::func::*; use crate::func::*;
use super::comparator::Comparator;
pub type NodeRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Node>; pub type NodeRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Node>;
pub type ReferenceRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Reference>; pub type ReferenceRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Reference>;
pub type TreeRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Tree>; pub type TreeRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Tree>;
@ -17,22 +19,29 @@ pub trait BinaryTrees<'a>: 'a {
type Reference: 'a; type Reference: 'a;
type Tree: 'a; type Tree: 'a;
type Key: 'a; type Key: 'a;
type Comparator: Comparator<Self::Key>;
type T: Monad<'a>; type T: Monad<'a>;
fn split(node: Self::Node) -> Split<'a, Self>; fn comparator(&self) -> &Self::Comparator;
fn to_tree(node: Self::Node) -> TreeRc<'a, Self>; fn split(&self, node: Self::Node) -> Split<'a, Self>;
fn resolve(reference: Self::Reference) -> Wrapped<'a, Self, NodeRc<'a, Self>>; fn to_tree(&self, node: Self::Node) -> TreeRc<'a, Self>;
fn equal(rhs: Self::Reference, lhs: Self::Reference) -> bool; fn resolve(&self, reference: Self::Reference) -> Wrapped<'a, Self, NodeRc<'a, Self>>;
fn refer(tree: Self::Tree) -> Option<ReferenceRc<'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> { pub trait BinaryTreesMutable<'a>: BinaryTrees<'a> {
fn join_key( fn join_key(
&self,
tl: Self::Tree, tl: Self::Tree,
key: KeyRc<'a, Self>, key: KeyRc<'a, Self>,
tr: Self::Tree, tr: Self::Tree,
) -> Wrapped<'a, Self, TreeRc<'a, Self>>; ) -> Wrapped<'a, Self, NodeRc<'a, Self>>;
fn join(tl: Self::Tree, tr: Self::Tree) -> Wrapped<'a, Self, TreeRc<'a, Self>>; fn join(&self, tl: Self::Tree, tr: Self::Tree) -> Wrapped<'a, Self, TreeRc<'a, Self>>;
fn split_key(tree: Self::Tree, key: KeyRc<'a, Self>) -> Wrapped<'a, Self, KeySplit<'a, Self>>; fn split_key(
&self,
tree: Self::Tree,
key: KeyRc<'a, Self>,
) -> Wrapped<'a, Self, KeySplit<'a, Self>>;
} }