Skip to content

Commit f186df4

Browse files
committed
Clean up whitespaces
1 parent 37a69fb commit f186df4

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/seq/index.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Rng;
2121

2222
/// A vector of indices.
23-
///
23+
///
2424
/// Multiple internal representations are possible.
2525
#[derive(Clone, Debug)]
2626
pub enum IndexVec {
@@ -36,9 +36,9 @@ impl IndexVec {
3636
&IndexVec::USize(ref v) => v.len(),
3737
}
3838
}
39-
39+
4040
/// Return the value at the given `index`.
41-
///
41+
///
4242
/// (Note: we cannot implement `std::ops::Index` because of lifetime
4343
/// restrictions.)
4444
pub fn index(&self, index: usize) -> usize {
@@ -63,7 +63,7 @@ impl IndexVec {
6363
&IndexVec::USize(ref v) => IndexVecIter::USize(v.iter()),
6464
}
6565
}
66-
66+
6767
/// Convert into an iterator over the indices as a sequence of `usize` values
6868
pub fn into_iter(self) -> IndexVecIntoIter {
6969
match self {
@@ -115,7 +115,7 @@ impl<'a> Iterator for IndexVecIter<'a> {
115115
&mut USize(ref mut iter) => iter.next().cloned(),
116116
}
117117
}
118-
118+
119119
fn size_hint(&self) -> (usize, Option<usize>) {
120120
match self {
121121
&IndexVecIter::U32(ref v) => v.size_hint(),
@@ -135,15 +135,15 @@ pub enum IndexVecIntoIter {
135135

136136
impl Iterator for IndexVecIntoIter {
137137
type Item = usize;
138-
138+
139139
fn next(&mut self) -> Option<Self::Item> {
140140
use self::IndexVecIntoIter::*;
141141
match self {
142142
&mut U32(ref mut v) => v.next().map(|i| i as usize),
143143
&mut USize(ref mut v) => v.next(),
144144
}
145145
}
146-
146+
147147
fn size_hint(&self) -> (usize, Option<usize>) {
148148
use self::IndexVecIntoIter::*;
149149
match self {
@@ -191,7 +191,7 @@ pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
191191
}
192192
let amount = amount as u32;
193193
let length = length as u32;
194-
194+
195195
// Choice of algorithm here depends on both length and amount. See:
196196
// https://github.com/rust-random/rand/pull/479
197197
// We do some calculations with f32. Accuracy is not very important.
@@ -222,7 +222,7 @@ pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
222222

223223
/// Randomly sample exactly `amount` indices from `0..length`, using Floyd's
224224
/// combination algorithm.
225-
///
225+
///
226226
/// The output values are fully shuffled. (Overhead is under 50%.)
227227
///
228228
/// This implementation uses `O(amount)` memory and `O(amount^2)` time.
@@ -233,7 +233,7 @@ fn sample_floyd<R>(rng: &mut R, length: u32, amount: u32) -> IndexVec
233233
// amounts this is slow due to Vec::insert performance, so we shuffle
234234
// afterwards. Benchmarks show little overhead from extra logic.
235235
let floyd_shuffle = amount < 50;
236-
236+
237237
debug_assert!(amount <= length);
238238
let mut indices = Vec::with_capacity(amount as usize);
239239
for j in length - amount .. length {
@@ -267,7 +267,7 @@ fn sample_floyd<R>(rng: &mut R, length: u32, amount: u32) -> IndexVec
267267
///
268268
/// This allocates the entire `length` of indices and randomizes only the first `amount`.
269269
/// It then truncates to `amount` and returns.
270-
///
270+
///
271271
/// This method is not appropriate for large `length` and potentially uses a lot
272272
/// of memory; because of this we only implement for `u32` index (which improves
273273
/// performance in all cases).
@@ -309,19 +309,19 @@ fn sample_rejection<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
309309
}
310310
indices.push(pos);
311311
}
312-
312+
313313
debug_assert_eq!(indices.len(), amount);
314314
IndexVec::from(indices)
315315
}
316316

317317
#[cfg(test)]
318318
mod test {
319319
use super::*;
320-
320+
321321
#[test]
322322
fn test_sample_boundaries() {
323323
let mut r = ::test::rng(404);
324-
324+
325325
assert_eq!(sample_inplace(&mut r, 0, 0).len(), 0);
326326
assert_eq!(sample_inplace(&mut r, 1, 0).len(), 0);
327327
assert_eq!(sample_inplace(&mut r, 1, 1).into_vec(), vec![0]);
@@ -331,43 +331,43 @@ mod test {
331331
assert_eq!(sample_floyd(&mut r, 0, 0).len(), 0);
332332
assert_eq!(sample_floyd(&mut r, 1, 0).len(), 0);
333333
assert_eq!(sample_floyd(&mut r, 1, 1).into_vec(), vec![0]);
334-
334+
335335
// These algorithms should be fast with big numbers. Test average.
336336
let sum: usize = sample_rejection(&mut r, 1 << 25, 10)
337337
.into_iter().sum();
338338
assert!(1 << 25 < sum && sum < (1 << 25) * 25);
339-
339+
340340
let sum: usize = sample_floyd(&mut r, 1 << 25, 10)
341341
.into_iter().sum();
342342
assert!(1 << 25 < sum && sum < (1 << 25) * 25);
343343
}
344-
344+
345345
#[test]
346346
fn test_sample_alg() {
347347
let seed_rng = ::test::rng;
348348

349349
// We can't test which algorithm is used directly, but Floyd's alg
350350
// should produce different results from the others. (Also, `inplace`
351351
// and `cached` currently use different sizes thus produce different results.)
352-
352+
353353
// A small length and relatively large amount should use inplace
354354
let (length, amount): (usize, usize) = (100, 50);
355355
let v1 = sample(&mut seed_rng(420), length, amount);
356356
let v2 = sample_inplace(&mut seed_rng(420), length as u32, amount as u32);
357357
assert!(v1.iter().all(|e| e < length));
358358
assert_eq!(v1, v2);
359-
359+
360360
// Test Floyd's alg does produce different results
361361
let v3 = sample_floyd(&mut seed_rng(420), length as u32, amount as u32);
362362
assert!(v1 != v3);
363-
363+
364364
// A large length and small amount should use Floyd
365365
let (length, amount): (usize, usize) = (1<<20, 50);
366366
let v1 = sample(&mut seed_rng(421), length, amount);
367367
let v2 = sample_floyd(&mut seed_rng(421), length as u32, amount as u32);
368368
assert!(v1.iter().all(|e| e < length));
369369
assert_eq!(v1, v2);
370-
370+
371371
// A large length and larger amount should use cache
372372
let (length, amount): (usize, usize) = (1<<20, 600);
373373
let v1 = sample(&mut seed_rng(422), length, amount);

0 commit comments

Comments
 (0)