diff options
Diffstat (limited to 'src/swarm/topology')
| -rw-r--r-- | src/swarm/topology/tests.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/swarm/topology/tests.rs b/src/swarm/topology/tests.rs index 807ea63..4069c0e 100644 --- a/src/swarm/topology/tests.rs +++ b/src/swarm/topology/tests.rs @@ -317,10 +317,11 @@ fn hub_degree_is_bounded_in_large_swarms() { /// their members' keys): as now (every node that gets it tells all its neighbours but /// the one it came from, over the links that work), and along the writer's tree. /// -/// The tree: every member's distance from the writer over the member list's graph (as -/// every node computes it alike), and each member's parent the neighbour it reaches -/// (as it tells its neighbours, `swarm::reach`) that comes first by distance, then pair -/// score, of those before it (by distance, then pair key: no cycles). Whoever has a +/// The tree (`swarm::tree`): every member's distance from the writer over the member +/// list's graph (as every node computes it alike), and each member's parent the +/// neighbour it reaches (as it tells its neighbours, `swarm::reach`) that comes first by +/// distance, then whether it reaches a member a hop closer, then pair score, of those +/// before it (by the same, then pair key: no cycles). Whoever has a /// change of the writer's passes it on to its children in the writer's tree, however /// it got it. A member with no parent it reaches waits for an announcement from a /// neighbour that has it (a pull), then passes it on to its own children. @@ -399,14 +400,21 @@ fn bench_writer_trees() { } depth_max = depth_max.max(depth.values().copied().max().unwrap_or(0)); // Each member's parent: one it reaches, before it. - let rank = |m: &str| (depth[m], key[m]); + // Whether a member reaches one a hop closer (the writer: yes). + let closer = |m: &str| { + depth[m] == 0 + || g[m] + .iter() + .any(|o| depth[o.as_str()] + 1 == depth[m] && works(m, o)) + }; + let rank = |m: &str| (depth[m], !closer(m), key[m]); let mut children: HashMap<&str, Vec<&str>> = HashMap::new(); for &m in &order[1..] { let parent = g[m] .iter() .map(String::as_str) .filter(|p| rank(p) < rank(m) && works(m, p)) - .min_by_key(|p| (depth[p], pair_score(p, m))); + .min_by_key(|p| (depth[p], !closer(p), pair_score(p, m))); if let Some(parent) = parent { children.entry(parent).or_default().push(m); } |
