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 8, 2018
1 parent 6225699 commit 40e7431
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ 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 if shuffled {
Expand All @@ -188,7 +188,7 @@ pub fn sample_indices<R>(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)
Expand Down

0 comments on commit 40e7431

Please sign in to comment.