pub trait ToUndirectedOp {
type Undirected;
// Required method
fn to_undirected(
&self,
layout: impl Into<Option<CsrLayout>>,
) -> Self::Undirected;
}Required Associated Types§
type Undirected
Required Methods§
Sourcefn to_undirected(
&self,
layout: impl Into<Option<CsrLayout>>,
) -> Self::Undirected
fn to_undirected( &self, layout: impl Into<Option<CsrLayout>>, ) -> Self::Undirected
Creates a new undirected graph from the edges of an existing graph.
Note, that this method creates a new graph with the same space requirements as the input graph.
§Example
use fso_graph_builder::prelude::*;
let graph: DirectedCsrGraph<u32> = GraphBuilder::new()
.edges(vec![(0, 1), (2, 0)])
.build();
assert_eq!(graph.out_degree(0), 1);
assert_eq!(graph.out_neighbors(0).as_slice(), &[1]);
assert_eq!(graph.in_degree(0), 1);
assert_eq!(graph.in_neighbors(0).as_slice(), &[2]);
let graph = graph.to_undirected(None);
assert_eq!(graph.degree(0), 2);
assert_eq!(graph.neighbors(0).as_slice(), &[1, 2]);This method accepts an optional CsrLayout as second parameter,
which has the same effect as described in [GraphBuilder::csr_layout]
§Example
use fso_graph_builder::prelude::*;
let graph: DirectedCsrGraph<u32> = GraphBuilder::new()
.edges(vec![(0, 2), (1, 0), (2, 0)])
.build();
// No layout specified, a default layput is chosen
let un_graph = graph.to_undirected(None);
let mut neighbors = un_graph.neighbors(0).copied().collect::<Vec<_>>();
neighbors.sort_unstable();
assert_eq!(neighbors, &[1, 2, 2]);
// The `Sorted` layout
let un_graph = graph.to_undirected(CsrLayout::Sorted);
assert_eq!(un_graph.neighbors(0).as_slice(), &[1, 2, 2]);
// The `Deduplicated` layout
let un_graph = graph.to_undirected(CsrLayout::Deduplicated);
assert_eq!(un_graph.neighbors(0).as_slice(), &[1, 2]);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".