diff --git a/book-radn b/book-radn index 343baf1..bb44e06 160000 --- a/book-radn +++ b/book-radn @@ -1 +1 @@ -Subproject commit 343baf150fe86ad6cd3594828068d42e7bc25b18 +Subproject commit bb44e06dea5b3a00585066063be00c4b3a976f70 diff --git a/src/flow.rs b/src/flow.rs index 60bd286..0d4dc51 100644 --- a/src/flow.rs +++ b/src/flow.rs @@ -1,3 +1,4 @@ //! Data structures and algorithms, independent of [`crate::core`] concepts. +pub mod binary; pub mod traversible; diff --git a/src/flow/binary.rs b/src/flow/binary.rs new file mode 100644 index 0000000..946c59f --- /dev/null +++ b/src/flow/binary.rs @@ -0,0 +1,30 @@ +use std::rc::Rc; + +use crate::func::*; + +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 Wrapped<'a, BT, A> = <>::T as WeakFunctor>::F<'a, A>; + +pub trait BinaryTrees<'a>: 'a { + type Node: 'a; + type Reference: 'a; + type Tree: 'a; + type Key: 'a; + + type T: 'a + Monad; + + fn split(node: Self::Node) -> Wrapped<'a, Self, Split<'a, Self>>; + fn to_tree(node: Self::Node) -> TreeRc<'a, Self>; + fn to_tree_construct(&self, node: Self::Node) -> TreeRc<'a, Self> { + Self::to_tree(node) + } + fn resolve(reference: Self::Reference) -> Wrapped<'a, Self, NodeRc<'a, Self>>; + fn equal(rhs: Self::Reference, lhs: Self::Reference) -> bool; + fn refer(tree: Self::Tree) -> Option>; +}