Bump rand from 0.5.5 to 0.6.1 (#1891)

* Bump rand from 0.5.5 to 0.6.1

Bumps [rand](https://github.com/rust-random/rand) from 0.5.5 to 0.6.1.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/commits)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Fix conflicts and deprecated usages

* Fix benches
This commit is contained in:
dependabot[bot] 2018-12-05 14:12:10 -08:00 committed by Sagar Dhawan
parent a29b307554
commit ad3e36a7ab
9 changed files with 28 additions and 27 deletions

5
Cargo.lock generated
View File

@ -1750,7 +1750,8 @@ dependencies = [
"matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pnet_datalink 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1944,7 +1945,7 @@ dependencies = [
"influx_db_client 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk 0.11.0",
]

View File

@ -86,7 +86,8 @@ log = "0.4.2"
matches = "0.1.6"
nix = "0.12.0"
pnet_datalink = "0.21.0"
rand = "0.5.1"
rand = "0.6.1"
rand_chacha = "0.1.0"
rayon = "1.0.0"
reqwest = "0.9.0"
ring = "0.13.2"

View File

@ -4,7 +4,7 @@ extern crate rocksdb;
extern crate solana;
extern crate test;
use rand::distributions::{Distribution, Range};
use rand::seq::SliceRandom;
use rand::{thread_rng, Rng};
use rocksdb::{Options, DB};
use solana::db_ledger::{DataCf, DbLedger, LedgerColumnFamilyRaw};
@ -94,13 +94,10 @@ fn bench_read_sequential(bench: &mut Bencher) {
setup_read_bench(&mut db_ledger, num_small_blobs, num_large_blobs, slot);
let num_reads = total_blobs / 15;
// Make range [0, total_blobs - 1]
let range = Range::new(0, num_small_blobs + num_large_blobs);
let mut rng = rand::thread_rng();
bench.iter(move || {
// Generate random starting point in that range, read num_reads blobs sequentially
let start_index = range.sample(&mut rng);
// Generate random starting point in the range [0, total_blobs - 1], read num_reads blobs sequentially
let start_index = rng.gen_range(0, num_small_blobs + num_large_blobs);
for i in start_index..start_index + num_reads {
let _ =
db_ledger
@ -129,14 +126,11 @@ fn bench_read_random(bench: &mut Bencher) {
let num_reads = total_blobs / 15;
// Make range [0, total_blobs - 1]
let range = Range::new(0, total_blobs);
// Generate a num_reads sized random sample of indexes in range [0, total_blobs - 1],
// simulating random reads
let mut rng = rand::thread_rng();
let indexes: Vec<usize> = (0..num_reads)
.map(|_| range.sample(&mut rng) as usize)
.map(|_| rng.gen_range(0, total_blobs) as usize)
.collect();
bench.iter(move || {
for i in indexes.iter() {
@ -161,7 +155,7 @@ fn bench_insert_data_blob_small(bench: &mut Bencher) {
let shared_blobs = entries.to_blobs();
let mut blob_locks: Vec<_> = shared_blobs.iter().map(|b| b.write().unwrap()).collect();
let mut blobs: Vec<&mut Blob> = blob_locks.iter_mut().map(|b| &mut **b).collect();
thread_rng().shuffle(&mut blobs);
blobs.shuffle(&mut thread_rng());
let slot = 0;
bench.iter(move || {
@ -188,7 +182,7 @@ fn bench_insert_data_blob_big(bench: &mut Bencher) {
let shared_blobs = entries.to_blobs();
let mut blob_locks: Vec<_> = shared_blobs.iter().map(|b| b.write().unwrap()).collect();
let mut blobs: Vec<&mut Blob> = blob_locks.iter_mut().map(|b| &mut **b).collect();
thread_rng().shuffle(&mut blobs);
blobs.shuffle(&mut thread_rng());
let slot = 0;
bench.iter(move || {

View File

@ -9,7 +9,7 @@ license = "Apache-2.0"
[dependencies]
influx_db_client = "0.3.6"
log = "0.4.2"
rand = "0.5.1"
rand = "0.6.1"
reqwest = "0.9.0"
lazy_static = "1.2.0"
solana-sdk = { path = "../sdk", version = "0.11.0" }

View File

@ -17,7 +17,7 @@ use crds_gossip_error::CrdsGossipError;
use crds_value::{CrdsValue, CrdsValueLabel};
use packet::BLOB_DATA_SIZE;
use rand;
use rand::distributions::{Distribution, Weighted, WeightedChoice};
use rand::distributions::{Distribution, WeightedIndex};
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use std::cmp;
@ -54,7 +54,7 @@ impl CrdsGossipPull {
self_id: Pubkey,
now: u64,
) -> Result<(Pubkey, Bloom<Hash>, CrdsValue), CrdsGossipError> {
let mut options: Vec<_> = crds
let options: Vec<_> = crds
.table
.values()
.filter_map(|v| v.value.contact_info())
@ -66,17 +66,18 @@ impl CrdsGossipPull {
1,
cmp::min(u64::from(u16::max_value()) - 1, (now - req_time) / 1024) as u32,
);
Weighted { weight, item }
(weight, item)
}).collect();
if options.is_empty() {
return Err(CrdsGossipError::NoPeers);
}
let filter = self.build_crds_filter(crds);
let random = WeightedChoice::new(&mut options).sample(&mut rand::thread_rng());
let index = WeightedIndex::new(options.iter().map(|weighted| weighted.0)).unwrap();
let random = index.sample(&mut rand::thread_rng());
let self_info = crds
.lookup(&CrdsValueLabel::ContactInfo(self_id))
.unwrap_or_else(|| panic!("self_id invalid {}", self_id));
Ok((random.id, filter, self_info.clone()))
Ok((options[random].1.id, filter, self_info.clone()))
}
/// time when a request to `from` was initiated

View File

@ -17,7 +17,8 @@ use crds_gossip_error::CrdsGossipError;
use crds_value::{CrdsValue, CrdsValueLabel};
use indexmap::map::IndexMap;
use packet::BLOB_DATA_SIZE;
use rand::{self, Rng};
use rand;
use rand::seq::SliceRandom;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use std::cmp;
@ -97,7 +98,7 @@ impl CrdsGossipPush {
pub fn new_push_messages(&mut self, crds: &Crds, now: u64) -> (Vec<Pubkey>, Vec<CrdsValue>) {
let max = self.active_set.len();
let mut nodes: Vec<_> = (0..max).collect();
rand::thread_rng().shuffle(&mut nodes);
nodes.shuffle(&mut rand::thread_rng());
let peers: Vec<Pubkey> = nodes
.into_iter()
.filter_map(|n| self.active_set.get_index(n))
@ -165,7 +166,7 @@ impl CrdsGossipPush {
let need = Self::compute_need(self.num_active, self.active_set.len(), ratio);
let mut new_items = HashMap::new();
let mut ixs: Vec<_> = (0..crds.table.len()).collect();
rand::thread_rng().shuffle(&mut ixs);
ixs.shuffle(&mut rand::thread_rng());
for ix in ixs {
let item = crds.table.get_index(ix);
@ -195,7 +196,7 @@ impl CrdsGossipPush {
}
}
let mut keys: Vec<Pubkey> = self.active_set.keys().cloned().collect();
rand::thread_rng().shuffle(&mut keys);
keys.shuffle(&mut rand::thread_rng());
let num = keys.len() / ratio;
for k in &keys[..num] {
self.active_set.remove(k);

View File

@ -130,3 +130,4 @@ extern crate untrusted;
extern crate matches;
extern crate rand;
extern crate rand_chacha;

View File

@ -1,6 +1,7 @@
//! The `signature` module provides functionality for public, and private keys.
use rand::{ChaChaRng, Rng, SeedableRng};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaChaRng;
use rayon::prelude::*;
use solana_sdk::signature::Keypair;
use untrusted::Input;

View File

@ -5,7 +5,8 @@
#[cfg(all(feature = "chacha", feature = "cuda"))]
use chacha_cuda::chacha_cbc_encrypt_file_many_keys;
use entry::EntryReceiver;
use rand::{ChaChaRng, Rng, SeedableRng};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaChaRng;
use result::{Error, Result};
use service::Service;
use solana_sdk::hash::Hash;