Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parallel unstable sort of nodes in Vicinity layer #9

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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