use std::borrow::Borrow;
use crate::NodeId;
mod labels;
pub use labels::*;
mod map_reduce;
pub use map_reduce::*;
pub trait MapReducer {
type Label: ToOwned + ?Sized;
type Error;
fn map(&mut self, node: NodeId)
-> Result<Option<<Self::Label as ToOwned>::Owned>, Self::Error>;
fn reduce<'a, I: Iterator<Item = &'a Self::Label>>(
&mut self,
first_label: <Self::Label as ToOwned>::Owned,
other_labels: I,
) -> Result<Option<<Self::Label as ToOwned>::Owned>, Self::Error>
where
Self::Label: 'a;
fn map_reduce(
&mut self,
node: NodeId,
successors_label: <Self::Label as ToOwned>::Owned,
) -> Result<Option<<Self::Label as ToOwned>::Owned>, Self::Error> {
match self.map(node)? {
Some(own_label) => self.reduce(own_label, [successors_label.borrow()].into_iter()),
None => Ok(Some(successors_label)),
}
}
fn on_node_traversed(
&mut self,
_node: NodeId,
_label: Option<&Self::Label>,
) -> Result<(), Self::Error> {
Ok(())
}
}