From 08d0404ee583c29693020e210e53a41762eb3b78 Mon Sep 17 00:00:00 2001 From: timofey <tim@ongoteam.yaconnect.com> Date: Sat, 20 May 2023 05:46:20 +0000 Subject: [PATCH] `flow::binary` --- book-radn | 2 +- src/flow.rs | 1 + src/flow/binary.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/flow/binary.rs 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<<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 Wrapped<'a, BT, A> = <<BT as BinaryTrees<'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<ReferenceRc<'a, Self>>; +}