///
/// Detect whether adding an edge from src to dst would create a cycle.
///
/// Uses Dijkstra's algorithm, which is significantly cheaper than the Bellman-Ford, but keeps
/// less context around paths on the way.
///
Detect whether adding an edge from src to dst would create a cycle.
Uses Dijkstra's algorithm, which is significantly cheaper than the Bellman-Ford, but keeps
less context around paths on the way.
Detect whether adding an edge from src to dst would create a cycle . Uses Dijkstra ' s algorithm which is significantly cheaper than the Bellman - Ford but keeps less context around paths on the way .
fn detect_cycle(
    &self,
    src_id: EntryId,
    dst_id: EntryId,
    should_include_edge: impl Fn(EdgeId) -> bool,
  ) -> bool {
    // Search either forward from the dst, or backward from the src.
    let (root, needle, direction) = {
      let out_from_dst = self.pg.neighbors(dst_id).count();
      let in_to_src = self
        .pg
        .neighbors_directed(src_id, Direction::Incoming)
        .count();
      if out_from_dst < in_to_src {
        (dst_id, src_id, Direction::Outgoing)
      } else {
        (src_id, dst_id, Direction::Incoming)
      }
    };
    // Search for an existing path from dst to src.
    let mut roots = VecDeque::new();
    roots.push_back(root);
    self
      .walk(roots, direction, should_include_edge)
      .any(|eid| eid == needle)
  }
fn detect_cycle ( & self , src_id : EntryId , dst_id : EntryId , should_include_edge : impl Fn ( EdgeId ) -> bool , ) -> bool { // Search either forward from the dst, or backward from the src. let ( root , needle , direction ) = { let out_from_dst = self . pg . neighbors ( dst_id ) . count ( ) ; let in_to_src = self . pg . neighbors_directed ( src_id , Direction :: Incoming ) . count ( ) ; if out_from_dst < in_to_src { ( dst_id , src_id , Direction :: Outgoing ) } else { ( src_id , dst_id , Direction :: Incoming ) } } ; // Search for an existing path from dst to src. let mut roots = VecDeque :: new ( ) ; roots . push_back ( root ) ; self . walk ( roots , direction , should_include_edge ) . any ( | eid | eid == needle ) }
Detect whether adding an edge from src to dst would create a cycle.
Detect whether adding an edge from src to dst would create a cycle .
&self
src_id
EntryId
dst_id
EntryId
should_include_edge
impl Fn(EdgeId) -> bool