You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
impl<N,E,Ix>Csr<N,E,Directed,Ix>whereIx:IndexType,{/// Create a new `Csr` from a sorted sequence of edges////// Edges **must** be sorted and unique, where the sort order is the default/// order for the pair *(u, v)* in Rust (*u* has priority).////// Computes in **O(|E| + |V|)** time./// # Example/// ```rust/// use petgraph::csr::Csr;/// use petgraph::prelude::*;////// let graph = Csr::<(),()>::from_sorted_edges(&[/// (0, 1), (0, 2),/// (1, 0), (1, 2), (1, 3),/// (2, 0),/// (3, 1),/// ]);/// ```pubfnfrom_sorted_edges<Edge>(edges:&[Edge]) -> Result<Self,EdgesNotSorted>whereEdge:Clone + IntoWeightedEdge<E,NodeId = NodeIndex<Ix>>,N:Default,{let max_node_id = match edges
.iter().map(|edge| {let(x, y, _) = edge.clone().into_weighted_edge();max(x.index(), y.index())}).max(){None => returnOk(Self::with_nodes(0)),Some(x) => x,};letmut self_ = Self::with_nodes(max_node_id + 1);letmut iter = edges.iter().cloned().peekable();{letmut rows = self_.row.iter_mut();letmut rstart = 0;letmut last_target;'outer:for(node, r)in(&mut rows).enumerate(){*r = rstart;
last_target = None;'inner:loop{ifletSome(edge) = iter.peek(){let(n, m, weight) = edge.clone().into_weighted_edge();// check that the edges are in increasing sequenceif node > n.index(){returnErr(EdgesNotSorted{first_error:(n.index(), m.index()),});}/* debug_assert!(node <= n.index(), concat!("edges are not sorted, ", "failed assertion source {:?} <= {:?} ", "for edge {:?}"), node, n, (n, m)); */if n.index() != node {break'inner;}// check that the edges are in increasing sequence/* debug_assert!(last_target.map_or(true, |x| m > x), "edges are not sorted, failed assertion {:?} < {:?}", last_target, m); */if !last_target.map_or(true, |x| m > x){returnErr(EdgesNotSorted{first_error:(n.index(), m.index()),});}
last_target = Some(m);
self_.column.push(m);
self_.edges.push(weight);
rstart += 1;}else{break'outer;}
iter.next();}}for r in rows {*r = rstart;}}Ok(self_)}}
The text was updated successfully, but these errors were encountered:
After check the source code, I think
from_sorted_edges
also apply to undirected csr.Source:
https://github.com/petgraph/petgraph/blame/2cf4969eefc8001a5135904fce2f8976e57d033d/src/csr.rs#L137
The text was updated successfully, but these errors were encountered: