|
|
@ -13,35 +13,41 @@ impl<V> Graph<V> for AdjacencyGraph<V>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
V: Ord + Clone,
|
|
|
|
V: Ord + Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fn nodes(&self) -> &BTreeSet<V> {
|
|
|
|
fn nodes(&self) -> BTreeSet<V> {
|
|
|
|
&self.nodes
|
|
|
|
self.nodes.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn adjacencies(&self) -> &BTreeMap<V, BTreeSet<V>> {
|
|
|
|
fn adjacencies(&self) -> BTreeMap<V, BTreeSet<V>> {
|
|
|
|
&self.adjacencies
|
|
|
|
self.adjacencies.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn edges(&self) -> BTreeMap<V, V> {
|
|
|
|
fn edges(&self) -> BTreeSet<(V, V)> {
|
|
|
|
self.adjacencies
|
|
|
|
self.adjacencies
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.flat_map(|(from, tos)| tos.iter().map(move |to| (from.clone(), to.clone())))
|
|
|
|
.flat_map(|(from, tos)| tos.iter().map(move |to| (from.clone(), to.clone())))
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// pub fn edges(&self) -> impl Iterator<Item = (&V, &V)> {
|
|
|
|
|
|
|
|
// self.adjacencies
|
|
|
|
|
|
|
|
// .iter()
|
|
|
|
|
|
|
|
// .flat_map(|(from, tos)| tos.iter().map(move |to| (from, to)))
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<V> Graph<V> for UndirectedGraph<V>
|
|
|
|
impl<V> Graph<V> for UndirectedGraph<V>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
V: Ord + Clone,
|
|
|
|
V: Ord + Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fn nodes(&self) -> &BTreeSet<V> {
|
|
|
|
fn nodes(&self) -> BTreeSet<V> {
|
|
|
|
self.directed.nodes()
|
|
|
|
self.directed.nodes()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn adjacencies(&self) -> &BTreeMap<V, BTreeSet<V>> {
|
|
|
|
fn adjacencies(&self) -> BTreeMap<V, BTreeSet<V>> {
|
|
|
|
self.directed.adjacencies()
|
|
|
|
self.directed.adjacencies()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn edges(&self) -> BTreeMap<V, V> {
|
|
|
|
fn edges(&self) -> BTreeSet<(V, V)> {
|
|
|
|
self.directed.edges()
|
|
|
|
self.directed.edges()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|