@@ -173,14 +173,13 @@ impl ExactSizeIterator for IndexVecIntoIter {}
173173/// Note that performance is significantly better over `u32` indices than over
174174/// `u64` indices. Because of this we hide the underlying type behind an
175175/// abstraction, `IndexVec`.
176- ///
176+ ///
177177/// If an allocation-free `no_std` function is required, it is suggested
178178/// to adapt the internal `sample_floyd` implementation.
179179///
180180/// Panics if `amount > length`.
181181pub fn sample < R > ( rng : & mut R , length : usize , amount : usize ) -> IndexVec
182- where R : Rng + ?Sized ,
183- {
182+ where R : Rng + ?Sized {
184183 if amount > length {
185184 panic ! ( "`amount` of samples must be less than or equal to `length`" ) ;
186185 }
@@ -227,8 +226,7 @@ pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
227226///
228227/// This implementation uses `O(amount)` memory and `O(amount^2)` time.
229228fn sample_floyd < R > ( rng : & mut R , length : u32 , amount : u32 ) -> IndexVec
230- where R : Rng + ?Sized ,
231- {
229+ where R : Rng + ?Sized {
232230 // For small amount we use Floyd's fully-shuffled variant. For larger
233231 // amounts this is slow due to Vec::insert performance, so we shuffle
234232 // afterwards. Benchmarks show little overhead from extra logic.
@@ -274,8 +272,7 @@ fn sample_floyd<R>(rng: &mut R, length: u32, amount: u32) -> IndexVec
274272///
275273/// Set-up is `O(length)` time and memory and shuffling is `O(amount)` time.
276274fn sample_inplace < R > ( rng : & mut R , length : u32 , amount : u32 ) -> IndexVec
277- where R : Rng + ?Sized ,
278- {
275+ where R : Rng + ?Sized {
279276 debug_assert ! ( amount <= length) ;
280277 let mut indices: Vec < u32 > = Vec :: with_capacity ( length as usize ) ;
281278 indices. extend ( 0 ..length) ;
@@ -290,13 +287,12 @@ fn sample_inplace<R>(rng: &mut R, length: u32, amount: u32) -> IndexVec
290287
291288/// Randomly sample exactly `amount` indices from `0..length`, using rejection
292289/// sampling.
293- ///
290+ ///
294291/// Since `amount <<< length` there is a low chance of a random sample in
295292/// `0..length` being a duplicate. We test for duplicates and resample where
296293/// necessary. The algorithm is `O(amount)` time and memory.
297294fn sample_rejection < R > ( rng : & mut R , length : usize , amount : usize ) -> IndexVec
298- where R : Rng + ?Sized ,
299- {
295+ where R : Rng + ?Sized {
300296 debug_assert ! ( amount < length) ;
301297 #[ cfg( feature="std" ) ] let mut cache = HashSet :: with_capacity ( amount) ;
302298 #[ cfg( not( feature="std" ) ) ] let mut cache = BTreeSet :: new ( ) ;
0 commit comments