33 * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44 */
55use crate :: { CentralityGraphAlgorithms , CsmGraph , GraphError , GraphView } ;
6+ use std:: collections:: HashSet ;
67use std:: collections:: VecDeque ;
78
89impl < 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