New to Rust.
I am attempting to replace a Arc<Vec> representation of visited nodes that required a lot of locking (part commented out) with a Vec of atomic bools. I can’t figure out how to do this. I don’t want and shouldn’t need to wrap visited in a mutex.
The result = line gives an error I dont understand –
mismatched types expected struct Arc<Mutex<Vec<usize>>>
found enum Result<bool, bool>
Also are those memory orderings correct?
pub fn process_node_dfs(node_index: usize, adjacency_matrix: Arc<Vec<Vec<bool>>>, pool: Arc<BaseThreadPool>, result: Arc<Mutex<Vec<usize>>>, visited: Arc<Vec<AtomicBool>>) {
let edges = &adjacency_matrix[node_index];
result.lock().unwrap().push(node_index);
for neighbour_index in 0..edges.len() {
// let mut visitedGuard: std::sync::MutexGuard<HashSet<usize>> = visited.lock().unwrap();
// if visitedGuard.contains(&neighbour_index) {
// std::mem::drop(visitedGuard);
// continue;
// }
// else {
// visitedGuard.insert(neighbour_index);
// }
// std::mem::drop(visitedGuard);
result = visited[neighbour_index].compare_exchange(false, true, std::sync::atomic::Ordering::Acquire, std::sync::atomic::Ordering::Relaxed);
let adjacency_matrix_clone: Arc<Vec<Vec<bool>>> = Arc::clone(&adjacency_matrix);
let pool_clone = Arc::clone(&pool);
let visited_clone = Arc::clone(&visited);
let result_clone = Arc::clone(&result);
pool.execute(move || process_node_dfs(neighbour_index, adjacency_matrix_clone, pool_clone, result_clone, visited_clone));
}
}