Skip to content

Commit

Permalink
fix distances in in-component algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ljeub-pometry committed Jan 2, 2025
1 parent 21f99d9 commit 0e3aca7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions raphtory/src/algorithms/components/in_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
prelude::GraphViewOps,
};
use itertools::Itertools;
use std::collections::{hash_map::Entry, HashMap, HashSet};
use std::collections::{hash_map::Entry, HashMap, HashSet, VecDeque};

#[derive(Clone, Debug, Default)]
struct InState {
Expand Down Expand Up @@ -111,20 +111,20 @@ pub fn in_component<'graph, G: GraphViewOps<'graph>>(
node: NodeView<G>,
) -> NodeState<'graph, usize, G> {
let mut in_components = HashMap::new();
let mut to_check_stack = Vec::new();
let mut to_check_stack = VecDeque::new();
node.in_neighbours().iter().for_each(|node| {
let id = node.node;
in_components.insert(id, 1usize);
to_check_stack.push((id, 1usize));
to_check_stack.push_back((id, 1usize));
});
while let Some((neighbour_id, d)) = to_check_stack.pop() {
while let Some((neighbour_id, d)) = to_check_stack.pop_front() {
let d = d + 1;
if let Some(neighbour) = &node.graph.node(neighbour_id) {
neighbour.in_neighbours().iter().for_each(|node| {
let id = node.node;
if let Entry::Vacant(entry) = in_components.entry(id) {
entry.insert(d);
to_check_stack.push((id, d));
to_check_stack.push_back((id, d));
}
});
}
Expand Down

0 comments on commit 0e3aca7

Please sign in to comment.