Skip to content

Commit

Permalink
sample_indices: update selection heuristics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dhardy committed Jun 7, 2018
1 parent 5971742 commit 5c6be22
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/seq.rs
Expand Up @@ -176,17 +176,17 @@ pub fn sample_indices<R>(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)
Expand Down

0 comments on commit 5c6be22

Please sign in to comment.