Skip to content

Commit 98889f2

Browse files
committed
sample_indices: update selection heuristics
Update with new benchmark data from `u32` impls of Floyd's and cached algorithms (inplace alg already used benchmarks from `u32` impl). Update Floyd's with a balanced model adequate for both shuffled and unshuffled versions.
1 parent d4da64e commit 98889f2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/seq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,17 +538,17 @@ pub fn sample_indices<R>(rng: &mut R, length: usize, amount: usize,
538538
// https://github.com/rust-lang-nursery/rand/pull/479
539539
// We do some calculations with u64 to avoid overflow.
540540

541-
if amount < 517 {
542-
const C: [[u64; 2]; 2] = [[1, 36], [200, 440]];
541+
if amount < 442 {
542+
const C: [[u64; 2]; 2] = [[5, 45], [50, 350]];
543543
let j = if length < 500_000 { 0 } else { 1 };
544-
let m4 = 4 * amount as u64;
544+
let m4 = 6 * amount as u64;
545545
if C[0][j] * (length as u64) < (C[1][j] + m4) * amount as u64 {
546546
sample_indices_inplace(rng, length, amount)
547547
} else {
548548
sample_indices_floyd(rng, length, amount, shuffled)
549549
}
550550
} else {
551-
const C: [[u64; 2]; 2] = [[1, 36], [62*40, 68*40]];
551+
const C: [[u64; 2]; 2] = [[1, 9], [590, 600]];
552552
let j = if length < 500_000 { 0 } else { 1 };
553553
if C[0][j] * (length as u64) < C[1][j] * amount as u64 {
554554
sample_indices_inplace(rng, length, amount)

0 commit comments

Comments
 (0)