implement calculate_centralities in a rusty way
I developed the following code to calculate the intermediation centrality of members, I would like to have an optimized version with iterators, do you feel like doing it ? (And of the integrated in RustyWot
?). On my side I can integrate it in LegacyWoT
;)
let wot_size = wot.size();
let mut centralities = vec![0;wot_size];
for i in 0..wot_size {
for j in 0..wot_size {
let paths = wot.get_paths(NodeId(i), NodeId(j), step_max);
let mut intermediate_members :Vec<NodeId> = Vec::new();
for path in paths {
if path.len() > 2 {
for node_id in &path[1..path.len()-1] {
if !intermediate_members.contains(node_id) {
intermediate_members.push(*node_id);
}
}
}
}
let centralities_copy = centralities.clone();
for node_id in intermediate_members {
let centrality = ¢ralities_copy[node_id.0];
if let Some(tmp) = centralities.get_mut(node_id.0) {
*tmp = *centrality + 1;
}
}
}
}