Skip to content

Commit 5c6be22

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 5971742 commit 5c6be22

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/seq.rs

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

179-
if amount < 517 {
180-
const C: [[u64; 2]; 2] = [[1, 36], [200, 440]];
179+
if amount < 442 {
180+
const C: [[u64; 2]; 2] = [[5, 45], [50, 350]];
181181
let j = if length < 500_000 { 0 } else { 1 };
182-
let m4 = 4 * amount as u64;
182+
let m4 = 6 * amount as u64;
183183
if C[0][j] * (length as u64) < (C[1][j] + m4) * amount as u64 {
184184
sample_indices_inplace(rng, length, amount)
185185
} else {
186186
sample_indices_floyd(rng, length, amount, shuffled)
187187
}
188188
} else {
189-
const C: [[u64; 2]; 2] = [[1, 36], [62*40, 68*40]];
189+
const C: [[u64; 2]; 2] = [[1, 9], [590, 600]];
190190
let j = if length < 500_000 { 0 } else { 1 };
191191
if C[0][j] * (length as u64) < C[1][j] * amount as u64 {
192192
sample_indices_inplace(rng, length, amount)

0 commit comments

Comments
 (0)