@@ -165,12 +165,12 @@ impl Rng {
165
165
}
166
166
167
167
/// Choose an item randomly, failing if values is empty
168
- fn choose < T : copy > ( values : ~ [ T ] ) -> T {
168
+ fn choose < T : copy > ( values : & [ T ] ) -> T {
169
169
self . choose_option ( values) . get ( )
170
170
}
171
171
172
172
/// Choose Some(item) randomly, returning None if values is empty
173
- fn choose_option < T : copy > ( values : ~ [ T ] ) -> Option < T > {
173
+ fn choose_option < T : copy > ( values : & [ T ] ) -> Option < T > {
174
174
if values. is_empty ( ) {
175
175
None
176
176
} else {
@@ -182,15 +182,15 @@ impl Rng {
182
182
* Choose an item respecting the relative weights, failing if the sum of
183
183
* the weights is 0
184
184
*/
185
- fn choose_weighted < T : copy > ( v : ~ [ Weighted < T > ] ) -> T {
185
+ fn choose_weighted < T : copy > ( v : & [ Weighted < T > ] ) -> T {
186
186
self . choose_weighted_option ( v) . get ( )
187
187
}
188
188
189
189
/**
190
190
* Choose Some(item) respecting the relative weights, returning none if
191
191
* the sum of the weights is 0
192
192
*/
193
- fn choose_weighted_option < T : copy > ( v : ~ [ Weighted < T > ] ) -> Option < T > {
193
+ fn choose_weighted_option < T : copy > ( v : & [ Weighted < T > ] ) -> Option < T > {
194
194
let mut total = 0 u;
195
195
for v. each |item| {
196
196
total += item. weight ;
@@ -213,7 +213,7 @@ impl Rng {
213
213
* Return a vec containing copies of the items, in order, where
214
214
* the weight of the item determines how many copies there are
215
215
*/
216
- fn weighted_vec < T : copy > ( v : ~ [ Weighted < T > ] ) -> ~[ T ] {
216
+ fn weighted_vec < T : copy > ( v : & [ Weighted < T > ] ) -> ~[ T ] {
217
217
let mut r = ~[ ] ;
218
218
for v. each |item| {
219
219
for uint:: range( 0 u, item. weight) |_i| {
@@ -224,14 +224,14 @@ impl Rng {
224
224
}
225
225
226
226
/// Shuffle a vec
227
- fn shuffle < T : copy > ( values : ~ [ T ] ) -> ~[ T ] {
228
- let mut m = vec:: to_mut ( values) ;
227
+ fn shuffle < T : copy > ( values : & [ T ] ) -> ~[ T ] {
228
+ let mut m = vec:: from_slice ( values) ;
229
229
self . shuffle_mut ( m) ;
230
- return vec :: from_mut ( m ) ;
230
+ return m ;
231
231
}
232
232
233
233
/// Shuffle a mutable vec in place
234
- fn shuffle_mut < T > ( & & values: ~ [ mut T ] ) {
234
+ fn shuffle_mut < T > ( values : & [ mut T ] ) {
235
235
let mut i = values. len ( ) ;
236
236
while i >= 2 u {
237
237
// invariant: elements with index >= i have been locked in place.
@@ -402,14 +402,14 @@ mod tests {
402
402
#[ test]
403
403
fn choose ( ) {
404
404
let r = rand:: Rng ( ) ;
405
- assert r. choose ( ~ [ 1 , 1 , 1 ] ) == 1 ;
405
+ assert r. choose ( [ 1 , 1 , 1 ] ) == 1 ;
406
406
}
407
407
408
408
#[ test]
409
409
fn choose_option ( ) {
410
410
let r = rand:: Rng ( ) ;
411
- assert r. choose_option ( ~ [ ] ) . is_none ( ) ;
412
- assert r. choose_option ( ~ [ 1 , 1 , 1 ] ) == Some ( 1 ) ;
411
+ assert r. choose_option :: < int > ( [ ] ) . is_none ( ) ;
412
+ assert r. choose_option ( [ 1 , 1 , 1 ] ) == Some ( 1 ) ;
413
413
}
414
414
415
415
#[ test]
@@ -431,7 +431,7 @@ mod tests {
431
431
{ weight: 0 u, item: 42 } ,
432
432
{ weight: 1 u, item: 43 }
433
433
] ) == Some ( 43 ) ;
434
- assert r. choose_weighted_option ( ~ [ ] ) . is_none ( ) ;
434
+ assert r. choose_weighted_option :: < int > ( [ ] ) . is_none ( ) ;
435
435
}
436
436
437
437
#[ test]
0 commit comments