pub trait NodeLabelsLender<'lend, __ImplBound: ImplBound = Ref<'lend, Self>>: Lender + Lending<'lend, __ImplBound, Lend = (usize, Self::IntoIterator)> {
type Label;
type IntoIterator: IntoIterator<Item = Self::Label>;
// Provided methods
fn into_labeled_pairs<'a>(self) -> IntoLabeledPairs<'a, Self> ⓘ
where Self: Sized + for<'b> NodeLabelsLender<'b, Label: Pair<Left = usize>> { ... }
fn into_pairs<'a>(self) -> IntoPairs<'a, Self> ⓘ
where Self: Sized + for<'b> NodeLabelsLender<'b, Label = usize> { ... }
}Expand description
Iteration on nodes and associated labels.
This trait is a Lender returning pairs given by a usize (a node of the
graph) and an IntoIterator, specified by the associated type
IntoIterator, over the labels associated with that node, specified by the
associated type Label (which is forced to be identical to the associated
type Item of the IntoIterator).
For those types we provide convenience type aliases LenderIntoIterator,
LenderIntoIter, and LenderLabel.
§Flattening Facilities
The methods into_pairs and
into_labeled_pairs convert a
NodeLabelsLender into an iterator of pairs (usize, usize) or labeled
pairs ((usize, usize), Label), respectively. These are convenience
methods that delegate to From trait implementations for IntoPairs
and IntoLabeledPairs.
§Extension of Lender Methods
Methods defined on Lender, such as Lender::zip, normally would
return a Lender, but not a NodeLabelsLender. However, the module
lenders contains implementations that automatically turn
such as a Lender into a NodeLabelsLender whenever it makes sense.
Thus, for example, one can take two graphs and merge easily the first half of the first one and the second half of the second one:
use webgraph::prelude::*;
use webgraph::graphs::random::ErdosRenyi;
use lender::*;
use itertools::Itertools;
// First random graph
let g = ErdosRenyi::new(100, 0.1, 0);
// Second random graph
let h = ErdosRenyi::new(100, 0.1, 1);
let mut v = VecGraph::new();
// Put first half of the first random graph in v
v.add_lender(g.iter().take(50));
// Put second half of the second random graph in v
v.add_lender(h.iter().skip(50));
let mut iter = v.iter();
for i in 0..50 {
itertools::assert_equal(v.successors(i), iter.next().unwrap().1);
}
let mut iter = h.iter().skip(50);
for i in 50..100 {
itertools::assert_equal(v.successors(i), iter.next().unwrap().1);
}VecGraph::add_lender
takes a NodeLabelsLender as an argument, but the implementations in the
module lenders makes the result of Lender::take and
Lender::skip a NodeLabelsLender.
§Propagation of implicit bounds
The definition of this trait emerged from a discussion on the Rust language
forum.
The purpose of the trait is to propagate the implicit bound appearing in the
definition Lender to the iterator returned by the associated type
IntoIterator. In this way, one can return iterators depending on the
internal state of the labeling. Without this additional trait, it would be
possible to return iterators whose state depends on the state of the lender,
but not on the state of the labeling.
ArcListGraph is the main
motivation for this trait.
Required Associated Types§
type Label
type IntoIterator: IntoIterator<Item = Self::Label>
Provided Methods§
Sourcefn into_labeled_pairs<'a>(self) -> IntoLabeledPairs<'a, Self> ⓘ
fn into_labeled_pairs<'a>(self) -> IntoLabeledPairs<'a, Self> ⓘ
Converts this lender into an iterator of labeled pairs of type
((usize, usize), Label), provided that the label type implements
Pair with Left = usize.
Typically, this method is used to convert a lender on a labeled graph into an iterator of labeled arcs.
This is a convenience method that delegates to the From trait
implementation.
Sourcefn into_pairs<'a>(self) -> IntoPairs<'a, Self> ⓘ
fn into_pairs<'a>(self) -> IntoPairs<'a, Self> ⓘ
Converts this lender into an iterator of pairs, provided that the label
type is usize.
Typically, this method is used to convert a lender on a graph into an iterator of arcs expressed as pairs.
This is a convenience method that delegates to the From trait
implementation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.