<commit_before>//! Iterators used by the graph implementations.

use std::ops;
use std::slice;
use std::marker::PhantomData;
use std::iter::{Iterator,DoubleEndedIterator};

use super::interface::{Id,Graph};


/// Iterator over the (node or edge) indices of a graph.
#[derive(Clone)]
pub struct Indices<T: Id>(ops::Range<usize>, PhantomData<T>);
impl<T: Id> Indices<T> {
    /// Create an `Indices` iterator over the given range.
    pub fn new(r: ops::Range<usize>) -> Self {
        Indices(r, PhantomData)
    }
}
impl<T: Id> Iterator for Indices<T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        self.0.next().map(|v| Id::new(v))
    }
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.0.size_hint()
    }
}



/// Iterator over some node's direct successors in a particular graph.
pub struct Successors<'a, G: Graph>
    where G: 'a, <G as Graph>::EdgeId: 'a {
    graph: &'a G,
    iter: slice::Iter<'a, <G as Graph>::EdgeId>
}
impl<'a,G: Graph> Successors<'a, G> {
    /// Create an iterator over the successors of a node using that node's
    /// outgoing edge list.
    pub fn new(g: &'a G, iter: slice::Iter<'a, <G as Graph>::EdgeId>) -> Self {
        Successors{graph: g, iter: iter}
    }
}
impl<'a,G: 'a + Graph> Iterator for Successors<'a,G> {
    type Item = <G as Graph>::NodeId;
    fn next(&mut self) -> Option<Self::Item> {
        self.iter.next().map(|id| self.graph.edge_target(*id))
    }
}

impl<'a,G: 'a + Graph> DoubleEndedIterator for Successors<'a,G> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.iter.next_back().map(|id| self.graph.edge_target(*id))
    }
}
<commit_msg>util/graph/iter: add newlines between top-level items<commit_after>//! Iterators used by the graph implementations.

use std::ops;
use std::slice;
use std::marker::PhantomData;
use std::iter::{Iterator,DoubleEndedIterator};

use super::interface::{Id,Graph};


/// Iterator over the (node or edge) indices of a graph.
#[derive(Clone)]
pub struct Indices<T: Id>(ops::Range<usize>, PhantomData<T>);

impl<T: Id> Indices<T> {
    /// Create an `Indices` iterator over the given range.
    pub fn new(r: ops::Range<usize>) -> Self {
        Indices(r, PhantomData)
    }
}

impl<T: Id> Iterator for Indices<T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        self.0.next().map(|v| Id::new(v))
    }
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.0.size_hint()
    }
}



/// Iterator over some node's direct successors in a particular graph.
pub struct Successors<'a, G: Graph>
    where G: 'a, <G as Graph>::EdgeId: 'a {
    graph: &'a G,
    iter: slice::Iter<'a, <G as Graph>::EdgeId>
}

impl<'a,G: Graph> Successors<'a, G> {
    /// Create an iterator over the successors of a node using that node's
    /// outgoing edge list.
    pub fn new(g: &'a G, iter: slice::Iter<'a, <G as Graph>::EdgeId>) -> Self {
        Successors{graph: g, iter: iter}
    }
}

impl<'a,G: 'a + Graph> Iterator for Successors<'a,G> {
    type Item = <G as Graph>::NodeId;
    fn next(&mut self) -> Option<Self::Item> {
        self.iter.next().map(|id| self.graph.edge_target(*id))
    }
}

impl<'a,G: 'a + Graph> DoubleEndedIterator for Successors<'a,G> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.iter.next_back().map(|id| self.graph.edge_target(*id))
    }
}

{'fraction_non_alphanumeric': 0.17723770005927683, 'fraction_numerical': 0.0011855364552459987, 'mean_word_length': 3.3548387096774195, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7021567', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1223, 'n_words': 331}