From 5c6be2287b27f779542640bc251b845961c8d8cd Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sat, 2 Jun 2018 15:22:47 +0100 Subject: [PATCH] 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. --- src/seq.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/seq.rs b/src/seq.rs index ff3a61801b..7d3c144453 100644 --- a/src/seq.rs +++ b/src/seq.rs @@ -176,17 +176,17 @@ pub fn sample_indices(rng: &mut R, length: usize, amount: usize, // https://github.com/rust-lang-nursery/rand/pull/479 // We do some calculations with u64 to avoid overflow. - if amount < 517 { - const C: [[u64; 2]; 2] = [[1, 36], [200, 440]]; + if amount < 442 { + const C: [[u64; 2]; 2] = [[5, 45], [50, 350]]; let j = if length < 500_000 { 0 } else { 1 }; - let m4 = 4 * amount as u64; + let m4 = 6 * amount as u64; if C[0][j] * (length as u64) < (C[1][j] + m4) * amount as u64 { sample_indices_inplace(rng, length, amount) } else { sample_indices_floyd(rng, length, amount, shuffled) } } else { - const C: [[u64; 2]; 2] = [[1, 36], [62*40, 68*40]]; + const C: [[u64; 2]; 2] = [[1, 9], [590, 600]]; let j = if length < 500_000 { 0 } else { 1 }; if C[0][j] * (length as u64) < C[1][j] * amount as u64 { sample_indices_inplace(rng, length, amount)