From 40e7431411331f756049a982729eee762b7e2edd 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 26d7d7e962..1357bc2d12 100644 --- a/src/seq.rs +++ b/src/seq.rs @@ -176,10 +176,10 @@ 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 if shuffled { @@ -188,7 +188,7 @@ pub fn sample_indices(rng: &mut R, length: usize, amount: usize, sample_indices_floyd(rng, length, amount) } } 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)