Skip to content

Commit

Permalink
Ranges used for copy_if
Browse files Browse the repository at this point in the history
  • Loading branch information
ErakhtinB committed Dec 20, 2024
1 parent 92d5f7c commit 0e9a69d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions core/network/impl/protocols/block_announce_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,17 @@ namespace kagome::network {
selected_peers.push_back(peer_id);
if (active_peers_.size() > max_parallel_downloads_) {
std::vector<PeerId> temp_peers;
std::copy_if(active_peers_.begin(),
active_peers_.end(),
std::back_inserter(temp_peers),
[&](const PeerId &p) { return p != peer_id; });
std::sample(temp_peers.begin(),
temp_peers.end(),
std::back_inserter(selected_peers),
max_parallel_downloads_ ? max_parallel_downloads_ - 1 : 0,
std::mt19937{std::random_device{}()});
std::ranges::copy_if(active_peers_,
std::back_inserter(temp_peers),
[&](const PeerId &p) { return p != peer_id; });
std::ranges::sample(temp_peers,
std::back_inserter(selected_peers),
max_parallel_downloads_ ? max_parallel_downloads_ - 1 : 0,
std::mt19937{std::random_device{}()});
} else {
std::copy_if(active_peers_.begin(),
active_peers_.end(),
std::back_inserter(selected_peers),
[&](const PeerId &p) { return p != peer_id; });
std::ranges::copy_if(active_peers_,
std::back_inserter(selected_peers),
[&](const PeerId &p) { return p != peer_id; });
}
}

Expand Down

0 comments on commit 0e9a69d

Please sign in to comment.