mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 11:55:04 +00:00
Code shuffle resiliently
This commit is contained in:
parent
ee00679331
commit
d061ab6c8e
1 changed files with 8 additions and 3 deletions
|
@ -309,8 +309,13 @@ pub fn analysis_stats(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
|
fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
|
||||||
for i in (1..slice.len()).rev() {
|
for i in 0..slice.len() {
|
||||||
let idx = rng.rand_range(0..i as u32) as usize;
|
randomize_first(rng, &mut slice[i..]);
|
||||||
slice.swap(idx, i)
|
}
|
||||||
|
|
||||||
|
fn randomize_first<T>(rng: &mut Rand32, slice: &mut [T]) {
|
||||||
|
assert!(!slice.is_empty());
|
||||||
|
let idx = rng.rand_range(0..slice.len() as u32) as usize;
|
||||||
|
slice.swap(0, idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue