Skip to content

Commit

Permalink
remove early-culling code from SCC (#1895)
Browse files Browse the repository at this point in the history
* remove early-culling code from SCC

* apply formatting

accidentally discarded my formatting changes in the last commit- doh!
  • Loading branch information
wyatt-joyner-pometry authored Dec 18, 2024
1 parent f00e7a8 commit 1539e7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
46 changes: 13 additions & 33 deletions raphtory/src/algorithms/components/scc.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
use std::{
collections::{HashMap, HashSet},
fmt::Debug,
};

use itertools::Itertools;
use std::collections::{HashMap, HashSet};

use crate::{
algorithms::algorithm_result::AlgorithmResult,
core::{entities::VID, state::compute_state::ComputeStateVec},
db::{
api::view::StaticGraphViewOps,
graph::node::NodeView,
task::{
context::Context,
node::eval_node::EvalNodeView,
task::{ATask, Job, Step},
task_runner::TaskRunner,
},
},
core::entities::VID,
db::{api::view::StaticGraphViewOps, graph::node::NodeView},
prelude::*,
};

Expand Down Expand Up @@ -88,13 +74,12 @@ where
result
}

pub fn strongly_connected_components<G>(
graph: &G,
threads: Option<usize>,
) -> AlgorithmResult<G, usize>
pub fn strongly_connected_components<G>(graph: &G) -> AlgorithmResult<G, usize>
where
G: StaticGraphViewOps,
{
// TODO: evaluate/improve this early-culling code
/*
#[derive(Clone, Debug, Default)]
struct SCCNode {
is_scc_node: bool,
Expand Down Expand Up @@ -147,22 +132,17 @@ where
.filter(|(_, state)| state.is_scc_node)
.map(|(vid, _)| VID(vid)),
);
*/

let results_type = std::any::type_name::<usize>();
let groups = tarjan_scc(&sub_graph);
let groups = tarjan_scc(graph);

let mut id = groups.len();
let mut res = HashMap::new();
for (id, group) in groups.into_iter().enumerate() {
for VID(node) in group {
res.insert(node, id);
}
}
for (node, state) in local.into_iter().enumerate() {
if !state.is_scc_node {
res.insert(node, id);
id += 1;
}
}

AlgorithmResult::new(
graph.clone(),
Expand Down Expand Up @@ -202,7 +182,7 @@ mod strongly_connected_components_tests {
}

test_storage!(&graph, |graph| {
let scc_nodes: HashSet<_> = strongly_connected_components(graph, None)
let scc_nodes: HashSet<_> = strongly_connected_components(graph)
.group_by()
.into_values()
.map(|mut v| {
Expand Down Expand Up @@ -246,7 +226,7 @@ mod strongly_connected_components_tests {
}

test_storage!(&graph, |graph| {
let scc_nodes: HashSet<_> = strongly_connected_components(graph, None)
let scc_nodes: HashSet<_> = strongly_connected_components(graph)
.group_by()
.into_values()
.map(|mut v| {
Expand All @@ -273,7 +253,7 @@ mod strongly_connected_components_tests {
}

test_storage!(&graph, |graph| {
let scc_nodes: HashSet<_> = strongly_connected_components(graph, None)
let scc_nodes: HashSet<_> = strongly_connected_components(graph)
.group_by()
.into_values()
.map(|mut v| {
Expand Down Expand Up @@ -308,7 +288,7 @@ mod strongly_connected_components_tests {
}

test_storage!(&graph, |graph| {
let scc_nodes: HashSet<_> = strongly_connected_components(graph, None)
let scc_nodes: HashSet<_> = strongly_connected_components(graph)
.group_by()
.into_values()
.map(|mut v| {
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/python/packages/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn weakly_connected_components(
pub fn strongly_connected_components(
g: &PyGraphView,
) -> AlgorithmResult<DynamicGraph, usize, usize> {
components::strongly_connected_components(&g.graph, None)
components::strongly_connected_components(&g.graph)
}

#[cfg(feature = "storage")]
Expand Down

0 comments on commit 1539e7e

Please sign in to comment.