use super::*;
pub struct NodesVisitor<'i, G: GraphEngine<'i> + ?Sized> {
graph: &'i G,
indexer: Box<dyn DoubleEndedIterator<Item = usize>>,
}
impl<'i, G> Debug for NodesVisitor<'i, G>
where
G: GraphEngine<'i> + ?Sized,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let name = type_name::<G>();
let nodes = self.graph.count_nodes();
f.debug_struct("NodesVisitor").field("graph", &name).field("nodes", &nodes).finish()
}
}
impl<'i, G> Iterator for NodesVisitor<'i, G>
where
G: GraphEngine<'i> + ?Sized,
{
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
todo!()
}
}
impl<'i, G> DoubleEndedIterator for NodesVisitor<'i, G>
where
G: GraphEngine<'i> + ?Sized,
{
fn next_back(&mut self) -> Option<Self::Item> {
todo!()
}
}
impl<'i, G> NodesVisitor<'i, G>
where
G: GraphEngine<'i> + ?Sized,
{
pub fn new<I>(graph: &'i G, indexer: I) -> Self
where
I: DoubleEndedIterator<Item = usize> + 'static,
{
Self { graph, indexer: Box::new(indexer) }
}
pub fn range<R>(graph: &'i G, range: R) -> Self
where
R: RangeBounds<usize>,
{
let start = match range.start_bound() {
Bound::Included(s) => *s,
Bound::Excluded(s) => *s + 1,
Bound::Unbounded => 0,
};
let end = match range.end_bound() {
Bound::Included(s) => *s + 1,
Bound::Excluded(s) => *s,
Bound::Unbounded => {
panic!("Upper bound must be specified")
}
};
Self { graph, indexer: Box::new(Range { start, end }) }
}
pub fn slice(graph: &'i G, slice: &'static [usize]) -> Self {
Self { graph, indexer: Box::new(slice.iter().copied()) }
}
}