Skip to content

Commit

Permalink
Merge pull request #9 from michaeljfazio/parallel-sort
Browse files Browse the repository at this point in the history
Use parallel unstable sort of nodes in Vicinity layer
  • Loading branch information
NicolasDP authored Jan 29, 2020
2 parents 5bb0244 + c8dfaa5 commit a482ad8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rand = "0.7"
hex = "0.4"
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0"
rayon = "1.3.0"

[dev-dependencies]
rand_chacha = "0.2"
Expand Down
4 changes: 3 additions & 1 deletion src/poldercast/vicinity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{GossipsBuilder, Id, Layer, Node, NodeProfile, Nodes, ViewBuilder};
use rayon::prelude::*;

const VICINITY_MAX_VIEW_SIZE: usize = 20;
const VICINITY_MAX_GOSSIP_LENGTH: usize = 10;
Expand Down Expand Up @@ -75,7 +76,8 @@ impl Vicinity {
mut profiles: Vec<&Node>,
max: usize,
) -> Vec<Id> {
profiles.sort_by(|left, right| {
// Use unstable parallel sort as total number of nodes can be quite large.
profiles.par_sort_unstable_by(|left, right| {
to.proximity(left.profile())
.cmp(&to.proximity(right.profile()))
});
Expand Down

0 comments on commit a482ad8

Please sign in to comment.