flow::keyed
This commit is contained in:
parent
ea69b8414d
commit
2105513959
@ -4,6 +4,7 @@
|
||||
|
||||
pub mod binary;
|
||||
pub mod comparator;
|
||||
pub mod keyed;
|
||||
pub mod query;
|
||||
pub mod speculative;
|
||||
pub mod traversible;
|
||||
|
@ -8,33 +8,28 @@ use std::fmt::Display;
|
||||
use crate::flow::comparator::*;
|
||||
use crate::func::{context::*, *};
|
||||
|
||||
use super::keyed::*;
|
||||
|
||||
pub type Split<BT> = (
|
||||
<BT as BinaryTrees>::Tree,
|
||||
<BT as BinaryTrees>::Tree,
|
||||
<BT as BinaryTrees>::Key,
|
||||
<BT as Keyed>::Key,
|
||||
);
|
||||
|
||||
pub type KeySplit<BT> = (<BT as BinaryTrees>::Tree, <BT as BinaryTrees>::Tree);
|
||||
|
||||
pub type BTWrap<'a, BT, A> = WrapC<'a, A, BT>;
|
||||
|
||||
pub trait BinaryTrees: Clone {
|
||||
pub trait BinaryTrees: Keyed {
|
||||
type Node: Send;
|
||||
type Reference: Send;
|
||||
type Tree: Send;
|
||||
type Key: Send + Clone;
|
||||
|
||||
fn split(&self, node: &Self::Node) -> Split<Self>;
|
||||
fn equal(&self, rl: &Self::Reference, rr: &Self::Reference) -> bool;
|
||||
fn refer(&self, tree: &Self::Tree) -> Option<Self::Reference>;
|
||||
}
|
||||
|
||||
pub trait WithComparator: BinaryTrees {
|
||||
type Comparator: Comparator<Self::Key>;
|
||||
|
||||
fn comparator(&self) -> &Self::Comparator;
|
||||
}
|
||||
|
||||
pub trait MonadTrees<'a>: MonadContext<'a> + BinaryTrees {
|
||||
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node>;
|
||||
}
|
||||
|
@ -84,7 +84,11 @@ fn matches_height(hl: u64, hr: u64, hp: u64) -> Result<(), BalancingError> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<BT: TreesHeight + WithComparator> WithComparator for BalancedTrees<BT> {
|
||||
impl<BT: Keyed> Keyed for BalancedTrees<BT> {
|
||||
type Key = BT::Key;
|
||||
}
|
||||
|
||||
impl<BT: WithComparator> WithComparator for BalancedTrees<BT> {
|
||||
type Comparator = BT::Comparator;
|
||||
|
||||
fn comparator(&self) -> &Self::Comparator {
|
||||
@ -96,7 +100,6 @@ impl<BT: TreesHeight> BinaryTrees for BalancedTrees<BT> {
|
||||
type Node = BT::Node;
|
||||
type Reference = (BT::Reference, u64);
|
||||
type Tree = BT::Tree;
|
||||
type Key = BT::Key;
|
||||
|
||||
fn split(&self, node: &Self::Node) -> Split<Self> {
|
||||
self.0.split(node)
|
||||
|
@ -58,6 +58,10 @@ pub trait BinaryTreesBindable<'a>: MonadTrees<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<BT: Keyed> Keyed for BoundTrees<BT> {
|
||||
type Key = BT::Key;
|
||||
}
|
||||
|
||||
impl<BT: WithComparator> WithComparator for BoundTrees<BT> {
|
||||
type Comparator = BT::Comparator;
|
||||
|
||||
@ -66,11 +70,10 @@ impl<BT: WithComparator> WithComparator for BoundTrees<BT> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<BT: WithComparator> BinaryTrees for BoundTrees<BT> {
|
||||
impl<BT: WithComparator + BinaryTrees> BinaryTrees for BoundTrees<BT> {
|
||||
type Node = BoundNode<Self::Key, BT::Node>;
|
||||
type Reference = Bound<Self::Key, BT::Reference>;
|
||||
type Tree = Bound<Self::Key, BT::Tree>;
|
||||
type Key = BT::Key;
|
||||
|
||||
fn split(&self, node: &Self::Node) -> Split<Self> {
|
||||
let (tl, tr, key) = self.0.split(&node.node);
|
||||
|
11
src/flow/keyed.rs
Normal file
11
src/flow/keyed.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use super::comparator::*;
|
||||
|
||||
pub trait Keyed: Clone {
|
||||
type Key: Send + Clone;
|
||||
}
|
||||
|
||||
pub trait WithComparator: Keyed {
|
||||
type Comparator: Comparator<Self::Key>;
|
||||
|
||||
fn comparator(&self) -> &Self::Comparator;
|
||||
}
|
@ -3,6 +3,7 @@ use std::{fmt::Display, marker::PhantomData, sync::Arc};
|
||||
use crate::flow::{
|
||||
binary::{balancing::*, bound::*, *},
|
||||
comparator::*,
|
||||
keyed::*,
|
||||
};
|
||||
use crate::func::{context::*, *};
|
||||
|
||||
@ -86,6 +87,10 @@ impl<'a, A: 'a + Send> FunctorContext<'a> for Trees<A> {
|
||||
type T = instances::solo::SoloInstance;
|
||||
}
|
||||
|
||||
impl<A: Send + Sync + Ord + Clone> Keyed for Trees<A> {
|
||||
type Key = A;
|
||||
}
|
||||
|
||||
impl<A: Send + Sync + Ord + Clone> WithComparator for Trees<A> {
|
||||
type Comparator = DefaultComparator;
|
||||
|
||||
@ -98,7 +103,6 @@ impl<A: Send + Sync + Ord + Clone> BinaryTrees for Trees<A> {
|
||||
type Node = Node<A>;
|
||||
type Reference = Reference<A>;
|
||||
type Tree = Tree<A>;
|
||||
type Key = A;
|
||||
|
||||
fn split(&self, node: &Self::Node) -> Split<Self> {
|
||||
(node.l.clone(), node.r.clone(), node.key.clone())
|
||||
|
@ -2,8 +2,9 @@ use std::{marker::PhantomData, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
flow::{
|
||||
binary::{balancing::*, bound::BinaryTreesBindable, bounds::*, *},
|
||||
binary::{balancing::*, bound::*, bounds::*, *},
|
||||
comparator::*,
|
||||
keyed::*,
|
||||
},
|
||||
func::context::*,
|
||||
rcore::*,
|
||||
@ -69,6 +70,17 @@ impl<
|
||||
type T = FallibleMonad<'a, Ctx, TreeContextError<'a, Ctx, A, E>>;
|
||||
}
|
||||
|
||||
impl<
|
||||
'a,
|
||||
Ctx: Context<'a>,
|
||||
A: Mentionable<'a, Ctx> + Clone,
|
||||
C: 'a + Comparator<A>,
|
||||
E: 'a + Send,
|
||||
> Keyed for TreeContext2<'a, Ctx, A, C, E>
|
||||
{
|
||||
type Key = A;
|
||||
}
|
||||
|
||||
impl<
|
||||
'a,
|
||||
Ctx: Context<'a>,
|
||||
@ -95,7 +107,6 @@ impl<
|
||||
type Node = Node<'a, Ctx, A>;
|
||||
type Reference = Point<'a, Ctx, Self::Node>;
|
||||
type Tree = Tree<'a, Ctx, A>;
|
||||
type Key = A;
|
||||
|
||||
fn split(&self, node: &Self::Node) -> crate::flow::binary::Split<Self> {
|
||||
(node.l.clone(), node.r.clone(), node.key.clone())
|
||||
|
Loading…
Reference in New Issue
Block a user