-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Bump rand to 0.8, rand_chacha to 0.3, getrandom to 0.2 #32871
Changes from 26 commits
7cb815a
0821cb7
4c99792
bdb5465
2e9c550
9a0a8ec
5d67cfc
6b8f63e
d4a6f09
53d12e3
79fb8d3
c8c1059
b87dd11
775da77
cab9648
2c99f5f
05bb142
6bf9c1d
f21bd05
0b10db3
3b2597c
37bb533
147c1e9
db48acc
39b5adf
fd77bc2
884dc52
2b45df5
295023a
7099108
2e09e57
9d44709
2b00f23
4718c51
7054869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,10 +308,16 @@ mod test { | |
); | ||
} | ||
|
||
fn generate_random_hash() -> Hash { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can try changing it to that and see if the bloom filter test passes. On the flipside, and I might be understanding this wrong, but it seems like the test is meant for random hashes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nah don't mess with it here |
||
let mut rng = rand::thread_rng(); | ||
let mut hash = [0u8; solana_sdk::hash::HASH_BYTES]; | ||
rng.fill(&mut hash); | ||
Hash::new_from_array(hash) | ||
} | ||
|
||
#[test] | ||
fn test_atomic_bloom() { | ||
let mut rng = rand::thread_rng(); | ||
let hash_values: Vec<_> = std::iter::repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) | ||
let hash_values: Vec<_> = std::iter::repeat_with(generate_random_hash) | ||
.take(1200) | ||
.collect(); | ||
let bloom: AtomicBloom<_> = Bloom::<Hash>::random(1287, 0.1, 7424).into(); | ||
|
@@ -328,7 +334,7 @@ mod test { | |
for hash_value in hash_values { | ||
assert!(bloom.contains(&hash_value)); | ||
} | ||
let false_positive = std::iter::repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) | ||
let false_positive = std::iter::repeat_with(generate_random_hash) | ||
.take(10_000) | ||
.filter(|hash_value| bloom.contains(hash_value)) | ||
.count(); | ||
|
@@ -340,7 +346,7 @@ mod test { | |
let mut rng = rand::thread_rng(); | ||
let keys: Vec<_> = std::iter::repeat_with(|| rng.gen()).take(5).collect(); | ||
let mut bloom = Bloom::<Hash>::new(9731, keys.clone()); | ||
let hash_values: Vec<_> = std::iter::repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) | ||
let hash_values: Vec<_> = std::iter::repeat_with(generate_random_hash) | ||
.take(1000) | ||
.collect(); | ||
for hash_value in &hash_values { | ||
|
@@ -375,10 +381,9 @@ mod test { | |
assert!(bloom.contains(hash_value)); | ||
} | ||
// Round trip, inserting new hash values. | ||
let more_hash_values: Vec<_> = | ||
std::iter::repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) | ||
.take(1000) | ||
.collect(); | ||
let more_hash_values: Vec<_> = std::iter::repeat_with(generate_random_hash) | ||
.take(1000) | ||
.collect(); | ||
let bloom: AtomicBloom<_> = bloom.into(); | ||
assert_eq!(bloom.num_bits, 9731); | ||
assert_eq!(bloom.bits.len(), (9731 + 63) / 64); | ||
|
@@ -391,7 +396,7 @@ mod test { | |
for hash_value in &more_hash_values { | ||
assert!(bloom.contains(hash_value)); | ||
} | ||
let false_positive = std::iter::repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) | ||
let false_positive = std::iter::repeat_with(generate_random_hash) | ||
.take(10_000) | ||
.filter(|hash_value| bloom.contains(hash_value)) | ||
.count(); | ||
|
@@ -410,7 +415,7 @@ mod test { | |
for hash_value in &more_hash_values { | ||
assert!(bloom.contains(hash_value)); | ||
} | ||
let false_positive = std::iter::repeat_with(|| solana_sdk::hash::new_rand(&mut rng)) | ||
let false_positive = std::iter::repeat_with(generate_random_hash) | ||
.take(10_000) | ||
.filter(|hash_value| bloom.contains(hash_value)) | ||
.count(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole method seems ripe for replacement with
tempfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truth