Skip to content

Commit 4bce435

Browse files
committed
Improved perf of deduplication in brandes_bfs_and_path_counting
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 6abdcac commit 4bce435

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ultragraph/src/types/storage/graph_csm/graph_csm_algo_centrality.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44
*/
55
use crate::{CentralityGraphAlgorithms, CsmGraph, GraphError, GraphView};
6+
use std::collections::HashSet;
67
use std::collections::VecDeque;
78

89
impl<N, W> CentralityGraphAlgorithms<N, W> for CsmGraph<N, W>
@@ -182,8 +183,8 @@ where
182183
for &neighbor in &self.forward_edges.targets[start..end] {
183184
neighbors_to_process.push(neighbor);
184185
}
186+
// For undirected, consider both forward and backward neighbors
185187
} else {
186-
// For undirected, consider both forward and backward neighbors
187188
let start_fwd = self.forward_edges.offsets[v];
188189
let end_fwd = self.forward_edges.offsets[v + 1];
189190
for &neighbor in &self.forward_edges.targets[start_fwd..end_fwd] {
@@ -194,8 +195,9 @@ where
194195
for &neighbor in &self.backward_edges.targets[start_bwd..end_bwd] {
195196
neighbors_to_process.push(neighbor);
196197
}
197-
neighbors_to_process.sort_unstable();
198-
neighbors_to_process.dedup(); // Remove duplicates if any
198+
// Use HashSet for efficient deduplication
199+
let unique_neighbors: HashSet<usize> = neighbors_to_process.drain(..).collect();
200+
neighbors_to_process.extend(unique_neighbors.into_iter());
199201
}
200202

201203
for &w in &neighbors_to_process {

0 commit comments

Comments
 (0)