From af4af62a277e6a6a7cdbcd2dd3097e632afca982 Mon Sep 17 00:00:00 2001 From: Edwin Navarro Date: Fri, 9 Jun 2023 12:57:54 -0700 Subject: [PATCH] Sort the todo_nodes (#897) --- rustworkx-core/src/token_swapper.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rustworkx-core/src/token_swapper.rs b/rustworkx-core/src/token_swapper.rs index 1aa84848d..065c969f8 100644 --- a/rustworkx-core/src/token_swapper.rs +++ b/rustworkx-core/src/token_swapper.rs @@ -23,6 +23,7 @@ use petgraph::visit::{ }; use petgraph::Directed; use petgraph::Direction::{Incoming, Outgoing}; +use rayon::prelude::*; use rayon_cond::CondIterator; use crate::connectivity::find_cycle; @@ -127,10 +128,11 @@ where .collect(); // todo_nodes are all the mapping entries where left != right - let todo_nodes: Vec = tokens + let mut todo_nodes: Vec = tokens .iter() .filter_map(|(node, dest)| if node != dest { Some(*node) } else { None }) .collect(); + todo_nodes.par_sort(); // Add initial edges to the digraph/sub_digraph for node in self.graph.node_identifiers() {